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

TOP

返回列表