65,210
社区成员
发帖
与我相关
我的任务
分享
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef vector<string> SIMPLE_WORDS;
int main()
{
SIMPLE_WORDS all_words;
string input;
while(cin >> input)
{
if(!all_words.empty() && (all_words.back() == input))
{
cout << "repeated word:" << input << endl;
return 0;
}
all_words.push_back(input);
}
copy(all_words.begin(), all_words.end(), ostream_iterator<string>(cout,"\n"));
return 0;
}
if(all_words.size() > 1 && input.compare(all_words.back()) == 0)
{
cout << " it's repeat... which is " << input << endl;
break;
}
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef vector<string> SIMPLE_WORDS;
int main()
{
SIMPLE_WORDS all_words;
string input;
while(cin >> input)
{
if(find(all_words.begin(), all_words.end(), input) != all_words.end())
{
cout << " it's repeat... which is " << input << endl;
break;
}
all_words.push_back(input);
}
struct{
void operator()(SIMPLE_WORDS::value_type& itr)
{
cout << itr << " ";
}
}print_key;
for_each(all_words.begin(), all_words.end(), print_key);
return 0;
}