题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
#include <iostream>
using namespace std;
#include <vector>
int main() {
string str;
getline(cin,str);
int cnt=0;
bool flag=false;
for(int i=0;i<str.length();i++){
string temp;
if(str[i]==' '){
if(cnt!=0){
cnt=0;
}
flag=true;
continue;
}
if(flag){
cnt++;
}
if(i==str.length()-1&&flag==false){
cout<<str.length();
return 0;
}
}
cout<<cnt;
return 0;
}
// 64 位输出请用 printf("%lld")
#实习,投递多份简历没人回复怎么办##悬赏#
