summaryrefslogtreecommitdiff
path: root/10327/flip.cpp
blob: 3f5c897960835dc8ecfc69a892a4da016e199cc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <vector>

//simple bubble sort for now, change later
std::vector<int> sort(std::vector<int> nums){
    int j, sorted = 0, temp;
    while(0 == sorted){
	sorted = 1;
	for(int i=0; i<nums.size()-1; i++){
	    j = i+1;
	    if(nums[i]>nums[j]){
		temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp;
		sorted = 0;
	    }
	}
    }
    return nums;
}

int main(){
    int n;
    while(std::cin>>n){
	std::vector<int> nums, sorted;
	int num;       
	while(n--){
	    std::cin>>num;
	    nums.push_back(num);
	}
	sorted = sort(nums);
	
	int mark[1000] = {0};
	int pos[1000] = {0};
	
	for(int i=0; i<nums.size(); i++){
	    for(int j=0; j<sorted.size(); j++){
		if(nums[i]==sorted[j] && mark[j]!=1){
		    pos[i] = j - i;
		    mark[j] = 1;
		    break;
		}
	    }
	}
	//
	std::cout<<"\n";
    }
}