Advertisement
Guest User

rotate

a guest
May 21st, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. // Rotate an array
  8. void rotateArray(vector<int> a, int d){
  9.  
  10. }
  11.  
  12. int main()
  13. {
  14.     string nd_temp;
  15.     getline(cin, nd_temp);
  16.  
  17.     vector<string> nd = split_string(nd_temp);
  18.  
  19.     int n = stoi(nd[0]);
  20.  
  21.     int d = stoi(nd[1]);
  22.  
  23.     string a_temp_temp;
  24.     getline(cin, a_temp_temp);
  25.  
  26.     vector<string> a_temp = split_string(a_temp_temp);
  27.  
  28.     vector<int> a(n);
  29.  
  30.     for (int i = 0; i < n; i++) {
  31.         int a_item = stoi(a_temp[i]);
  32.  
  33.         a[i] = a_item;
  34.     }
  35.  
  36.     rotateArray(a, d);
  37.  
  38.     return 0;
  39. }
  40.  
  41. vector<string> split_string(string input_string) {
  42.     string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  43.         return x == y and x == ' ';
  44.     });
  45.  
  46.     input_string.erase(new_end, input_string.end());
  47.  
  48.     while (input_string[input_string.length() - 1] == ' ') {
  49.         input_string.pop_back();
  50.     }
  51.  
  52.     vector<string> splits;
  53.     char delimiter = ' ';
  54.  
  55.     size_t i = 0;
  56.     size_t pos = input_string.find(delimiter);
  57.  
  58.     while (pos != string::npos) {
  59.         splits.push_back(input_string.substr(i, pos - i));
  60.  
  61.         i = pos + 1;
  62.         pos = input_string.find(delimiter, i);
  63.     }
  64.  
  65.     splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  66.  
  67.     return splits;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement