统计单词 题解

题目在主页,如有出错请指出
1.

include <bits/stdc++.h>

using namespace std;

int main()
{
string s;
int cnt = 0;
while (cin >> s && s != "*")
cnt++;
cout << cnt << endl;
return 0;
}
2.

include <bits/stdc++.h>

using namespace std;

int main()
{
string s;
getline(cin, s);
int len = s.size();
s = ' ' + s;
int cnt = 0;
for (int i = 1; i <= len; i++)
if ((islower(s[i]) || isupper(s[i])) && s[i - 1] == ' ') cnt++;
cout << cnt << endl;
return 0;
}

posted @ 2025-05-16 18:54  嵇若凌  阅读(14)  评论(0)    收藏  举报