-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindDashuibi.cpp
51 lines (45 loc) · 1019 Bytes
/
FindDashuibi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// FindDashuibi.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
using namespace std;
string findDashuibi(vector<string>& str,size_t num);
int _tmain(int argc, _TCHAR* argv[])
{
//vector<string> str(5);
//str.insert(str.begin(),"ayumi");
//str.insert(str.begin() + 1,"ayumi");
//str.insert(str.begin() + 2,"ammi");
//str.insert(str.begin() + 3,"ayumi");
//str.insert(str.begin() + 4,"mikku");
//str.shrink_to_fit();
istream_iterator<string> ini_it(cin);
istream_iterator<string> eof;
vector<string> str(ini_it,eof);
//ostream_iterator<string> out_iter(cout);
/*copy(ini_it,eof,str.begin());*/
auto s = findDashuibi(str,str.size());
cout<<"Dashuibi is "<<s<<endl;
system("pause");
return 0;
}
string findDashuibi(vector<string>& str,size_t num)
{
int nTimes = 0;
string candicate;
for(size_t i = 0;i < num;i++)
{
if(nTimes == 0)
{
candicate = str[i];
nTimes = 1;
}
else
{
if(candicate == str[i])
nTimes++;
else
nTimes--;
}
}
return candicate;
}