想看題目請點我
#include <iostream> using namespace std; int main (){ string input ; while(getline(cin,input)) { int word = 0 , flag = 0; for(int i = 0 ; i <= input.length() ; i++) { if((input[i] >= 'A' && input[i] <= 'Z') || (input[i] >= 'a' && input[i] <= 'z')) flag = 1 ; else { if(flag==1) { word++ ; flag = 0 ; } } } cout << word << endl ; } }