Guest User

Untitled

a guest
Jul 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. // Complete the jumpingOnClouds function below.
  8. int jumpingOnClouds(vector<int> c) {
  9. int iRet = 0;
  10. for(int i = 0; i <= c.size() - 2; ++i) {
  11. if ( c[i+2] == 0 ) {
  12. i += 1;
  13. }
  14. iRet++;
  15. }
  16. return iRet;
  17. }
  18.  
  19. int main()
  20. {
  21. ofstream fout(getenv("OUTPUT_PATH"));
  22.  
  23. int n;
  24. cin >> n;
  25. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  26.  
  27. string c_temp_temp;
  28. getline(cin, c_temp_temp);
  29.  
  30. vector<string> c_temp = split_string(c_temp_temp);
  31.  
  32. vector<int> c(n);
  33.  
  34. for (int i = 0; i < n; i++) {
  35. int c_item = stoi(c_temp[i]);
  36.  
  37. c[i] = c_item;
  38. }
  39.  
  40. int result = jumpingOnClouds(c);
  41.  
  42. fout << result << "\n";
  43.  
  44. fout.close();
  45.  
  46. return 0;
  47. }
  48.  
  49. vector<string> split_string(string input_string) {
  50. string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  51. return x == y and x == ' ';
  52. });
  53.  
  54. input_string.erase(new_end, input_string.end());
  55.  
  56. while (input_string[input_string.length() - 1] == ' ') {
  57. input_string.pop_back();
  58. }
  59.  
  60. vector<string> splits;
  61. char delimiter = ' ';
  62.  
  63. size_t i = 0;
  64. size_t pos = input_string.find(delimiter);
  65.  
  66. while (pos != string::npos) {
  67. splits.push_back(input_string.substr(i, pos - i));
  68.  
  69. i = pos + 1;
  70. pos = input_string.find(delimiter, i);
  71. }
  72.  
  73. splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  74.  
  75. return splits;
  76. }
Add Comment
Please, Sign In to add comment