字符串流做法
#include <iostream>
#include <cstring>
#include <algorithm>
#include <sstream>
using namespace std;
int main()
{
string s, c;
getline(cin, s);
s.pop_back();//直接去掉末尾的英文句号
stringstream ssin(s);//引入字符串流读入句中的单词
string str;
int cnt = 0;
//逐个判断每个单词,得出最长的单词
while (ssin >> str) if (str.length() > cnt) cnt = str.length(), c = str;
cout << c << endl;
return 0;
}
好牛,都忘记了有这个输入方式
你这代码如果单词都相当的情况下如何处理
都相等的话 那就是第一个呀 后面的都不大于第一个所以存下来的就只是第一个的
哦,明白了明白了,