题目:字符串与字符
分析:错误理解: 单词与单词一定有空 正确理解:单词与单词之间一定有非英文字符
注意:初始化
#include "sstream"
#include "string"
#include "iostream"
using namespace std
;
int main()
{
string s
;int flag
,counter
;
while(getline(cin
,s
))
{
counter
=0;flag
=1;
for(int i
=0;i
<s
.length();i
++)
{
if(s
[i
]>='a'&&s
[i
]<='z' ||s
[i
]>='A'&&s
[i
]<='Z')
{
if(flag
)
{
counter
++;
flag
=0;
}
}
else
{
flag
=1;
}
}
cout
<<counter
<<endl
;
}
}
转载请注明原文地址: https://yun.8miu.com/read-137886.html