求解答,其他字符的資料輸出一直錯誤

#include <bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
string s;
while(getline(cin,s))
{
int a[5]={0};
int x=s.length(),b;
for(int i=0;i<x;i++)
{
if(s[i]!='\0'){
if(s[i]>='A'&&s[i]<='Z')a[0]+=1;//大寫字母
if(s[i]>='a'&&s[i]<='z')a[1]+=1;//小寫
if(s[i]>='0'&&s[i]<='9')a[2]+=1;//數字
if(s[i]==' '||s[i]=='\t')a[3]+=1;//空格
else a[4]+=1;//其他
}
}
printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
}
return 0;
}
uj5u.com熱心網友回復:
因為統計多了,從第二個if開始在每個if前面加一個else,就不會出錯了轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/27687.html
標籤:C++ 語言
上一篇:C語言題目急求
下一篇:取消對NULL指標xxx的參考
