-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax_color.cpp
More file actions
76 lines (68 loc) · 873 Bytes
/
max_color.cpp
File metadata and controls
76 lines (68 loc) · 873 Bytes
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include"header_file.h"
#include<string.h>
using namespace std;
void add_color(vector<string> v1,vector<int> v2,string s)
{
if(v1.size()==0)
{
v1.push_back(s);
v2.push_back(1);
}
else
{
int i=0;
for(;i<v1.size();)
{
if(!strcmp(v1[i].c_str(),s.c_str()))
{
v2[i]++;
//i++;
break;
}
else
{
i++;
}
}
if(i==v1.size())
{
v1.push_back(s);
v2.push_back(1);
}
}
}
int find_max(vector<string> v1,vector<int> v2)
{
int max;
max=0;
for(int i=0;i<v2.size()-1;i++)
{
for(int j=i+1;j<v2.size();j++)
{
if(v2[i]<=v2[j])
{
max=j;
}
}
}
return max;
}
int main(void)
{
int N;
cout<<"input N:";
cin>>N;
vector<string> v1;
vector<int> v2;
//string s;
while(N)
{
string s;
cin>>s;
add_color(v1,v2,s);
N--;
}
cout<<endl;
int max=find_max(v1,v2);
cout<<v1[max]<<endl;
}