#include<iostream> #include<vector> #include<string> #include <algorithm> #include <math.h> using namespace std; int main() { string s; getline(cin,s); string str= ""; bool flag = false; vector<string> v; for(int i=0; i<s.size(); i++){ if(s[i] != ' '){ str+=s[i]; flag = true; }else{ if(flag) { v.push_back(str); flag = false; str = ""; } } } if(flag){ v.push_back(str); } printf("%d",v.size()); return 0; } |
Double click to view unformatted code.