64,685
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
int main(){
string str, pre;
cout << "Enter words: " << endl;
while(cin >> str){
if (pre == str){
cout << str << endl;
break;
}
pre = str;
}
if(pre == str && !str.empty())
cout << "The repeated word is: " << str << endl;
else
cout << "No repeated word." << endl;
return 0;
}
int main(int argc , char **argv)
{
string str, pre;
cout << "Enter words: " << endl;
while(cin >> str){
if (pre == str){
cout << str << endl;
break;
}
else
{
pre = str;
str.clear();
}
}
if(!str.empty())
cout << "The repeated word is: " << str << endl;
else
cout << "No repeated word." << endl;
return 0;
};