|
- #include"iostream"
- using namespace std;
- void main()
- {
- char str[100];
- int a,b,c,d;
- a=b=c=d=0;
- int i=0;
- gets(str); //鍵入字符串
- while(str[i]) //以回車結束,‘\0’的ASKII碼是“0”
- {
- if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')
- a++; //字母個數
- else
- if(str[i]>='0'&&str[i]<='9')
- b++; //數字個數
- else
- if(str[i]==' ')
- c++; //空格個數
- else
- d++; //其他
- i++;
- }
- cout<<"字母="<<a<<endl // 輸出
- <<"數字="<<b<<endl
- <<"空格="<<c<<endl
- <<"其他="<<d<<endl;
- }
復制代碼
|
|