返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int n=0;
  7.     char str[100];
  8.     cout<<"請輸入任一句子(請判斷句子中有幾個單字): "<<endl;
  9.     cin.getline(str,100);
  10.     for(int i=0; str[i]!=NULL; i++)
  11.     {
  12.           if((int(str[i])>=65 && int(str[i])<=90)||(int(str[i])>=97 && int(str[i])<=122))
  13.         {
  14.             n++;
  15.             if((int(str[i+1])>=65 && int(str[i+1])<=90)||(int(str[i+1])>=97 && int(str[i+1])<=122))
  16.                 n--;     
  17.         }      
  18.     }
  19.     cout<<endl<<"您輸入的句子中, 有"<<n<<"個單字"<<endl;
  20.     system("pause");
  21.     return 0;   
  22. }
複製代碼

TOP

返回列表