题解 | #字符串最后一个单词的长度#

字符串最后一个单词的长度

http://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da

首先需要了解C++输入cin每次只能读入一个(不含空格)字符串且遇到回车键就会结束 #include using namespace std; int main() { string s; while(cin>>s)//遇到回车键就会结束输入,即回车前的单词为我们所统计的最后字符串 cout<<s.length(); return 0;

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务