summaryrefslogtreecommitdiff
path: root/10327
diff options
context:
space:
mode:
authorAditya Naik2018-10-09 15:23:14 -0400
committerAditya Naik2018-10-09 15:23:14 -0400
commit2df9007ad5a981faf3506250b81e0e3bdbe8af79 (patch)
tree55a4e0ef3bf317d54c9818efcd8676b53117f9e4 /10327
parent01ab905a0603b4fe35bf438bec39d48f3ad61fe2 (diff)
added flip
Diffstat (limited to '10327')
-rw-r--r--10327/flip.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/10327/flip.cpp b/10327/flip.cpp
new file mode 100644
index 0000000..5ead08c
--- /dev/null
+++ b/10327/flip.cpp
@@ -0,0 +1,43 @@
+#include <iostream>
+#include <vector>
+
+//simple bubble sort for now, change later
+vector<int> sort(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){
+ vector<int> nums, sorted, pos;
+ int num;
+ while(n--){
+ std::cin>>num;
+ nums.push_back(num);
+ }
+ sorted = sort(nums);
+
+ int nums_idex=0;
+ for(int sort_idex=0;
+ i<sorted.size() && nums_idex < sorted.size(); i++){
+ if(sorted[sort_idex] == nums[nums_idex]){
+ pos.push_back(nums_idex - sort_idex);
+ nums_idex++;
+ }
+ }
+
+ }
+}