AI题库 · GESP-C++三级题库
题目分享 #21303
假设英文句子由若干词构成。下面C++代码统计输出的词数是( )。
int main()
{
string str="gEsP is Interesting !";
int x = str.length();
int nwords = 0;
for(int i = 0; i < x; i++)
if (str[i]==' '){
nwords++;
while(str[++i]==' ') ;
}
cout << nwords << endl;
cout << endl;
return 0;
}
A
1
B
2
C
3
D
4
AI题库 · 编程考级与信奥赛真题库
查看答案 →
复制链接后可在微信、QQ、小红书等平台粘贴分享;答案与解析在题目页。