C ++中最后一个字的长度
因此,如果输入就像“我喜欢编程”,那么输出将为11
为了解决这个问题,我们将遵循以下步骤-
n:=0
对于字符串中的每个单词temp-
n:=温度大小
返回n
示例
让我们看下面的实现以更好地理解-
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int lengthOfLastWord(string s){
stringstream str(s);
string temp;
int n = 0;
while (str >> temp)
n = temp.size();
return n;
}
};
main(){
Solution ob;
cout << (ob.lengthOfLastWord("I love Programming"));
}输入值
"I love Programming"
输出结果
11
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短