Advertisement
StoneHaos

misha_sr5

Jun 29th, 2020
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main(void) {
  7.     string str;
  8.     getline(cin, str);
  9.     int k, count = 0;
  10.     cin >> k;
  11.  
  12.     bool space = true;
  13.     for (int i = 0; i < str.size(); i ++) {
  14.         if (space && str[i] != ' ') {
  15.             count ++;
  16.             space = false;
  17.         }
  18.         else if (!space && str[i] == ' ')
  19.             space = true;
  20.         if (i == k) {
  21.             cout << count <<endl;
  22.             return 0;
  23.         }
  24.     }
  25.     cout << "error" <<endl;
  26.     return 1;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement