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 红包祝福语简短10字
18 周六早晨祝福语简短