SHARE
TWEET

Untitled

a guest Jan 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using std::cin;
  8. using std::cout;
  9.  
  10. using std::ifstream;
  11.  
  12. using std::vector;
  13. using std::sort;
  14.  
  15. using std::max;
  16.  
  17. int divide(vector<int> input, int left, int right) {
  18.  
  19.     int nr = 0;
  20.  
  21.     vector<int> bck = input;
  22.  
  23.     sort(input.begin(), input.end(), [](int a, int b) {
  24.         return a < b;
  25.     });
  26.  
  27.     for (int i = 0; i < input.size(); i++) {
  28.         if (bck[i] != input[i]) nr++;
  29.     }
  30.  
  31.     return nr;
  32. }
  33.  
  34. int main(){
  35.  
  36.     ifstream in("input.in");
  37.  
  38.     vector<int> input; int x;
  39.  
  40.     while (in >> x) {
  41.         input.push_back(x);
  42.     }
  43.  
  44.     cout << divide(input, 0, input.size() - 1);
  45.    
  46. }
  47.  
  48. //input: 1 2 9 11 4 6 10 15
  49. //output: 5
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top