求輸入的字符的個數(字母,數字,空格,其他)

 #include <iostream>
using namespace std;
int main ()
{char c;
 int letters=0,space=0,digit=0,other=0;
 cout<<"enter one line::"<<endl;
 while((c=getchar())!='/n')
 {if (c>='a' && c<='z'||c>='A' && c<='Z')
     letters++;
  else if (c==' ')
     space++;
  else if (c>='0' && c<='9')
     digit++;
  else
     other++;
  }
  cout<<"letter:"<<letters<<", space:"<<space<<", digit:"<<digit<<", other:"<<other<<endl;
  return 0;
  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章