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
热门推荐
5 短祝福语简短暖心
10 结婚祝福语粤语大全简短
11 晚上祝福语女生文案简短
12 法语妈妈生日祝福语简短
13 药厂开工祝福语大全简短
14 蛋糕节日祝福语简短英文
15 跨年的生日祝福语简短
16 文案祝福语英文短句简短
17 在家聚餐婚礼祝福语简短
18 学生节祝福语大全简短