#include
(5488)#include
using namespace std;
int jishu(string str) {
int n = str.size();
cout << n << endl;
cout << str<< endl;
int flag = 0;
for (int i = 0; i < n; i++) {
char a = str[i];
if (str[i] != ' ') {
flag++;
}
else flag = 0;
}
return flag;
}
int main() {
string str = {0};
cout << "请输入字符串!" << endl;
//cin >> str;
getline(cin,str);
int n = jishu(str);
cout << n << endl;
return 0;
}
(5488)#include
using namespace std;
int jishu(string str) {
int n = str.size();
cout << n << endl;
cout << str<< endl;
int flag = 0;
for (int i = 0; i < n; i++) {
char a = str[i];
if (str[i] != ' ') {
flag++;
}
else flag = 0;
}
return flag;
}
int main() {
string str = {0};
cout << "请输入字符串!" << endl;
//cin >> str;
getline(cin,str);
int n = jishu(str);
cout << n << endl;
return 0;
}
我已经通过这道算法题! 计算字符串最后一个单词的长度,单词以空格隔开。
https://gw-c.nowcoder.com/api/sparta/jump/link?link=https%3A%2F%2Fwww.nowcoder.com%2FquestionTerminal%2F8c949ea5f36f422594b306a2300315da
全部评论
相关推荐
点赞 评论 收藏
分享
查看18道真题和解析
点赞 评论 收藏
分享