-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecnuoj2852.cpp
44 lines (44 loc) · 948 Bytes
/
ecnuoj2852.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
#include<string>
#include<vector>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
double maxratio(string s,char &maxchar)
{
int countn = 0;
maxchar = ' ';
char thischar = ' ';
double maxnum = -1;
double thisnum = -1;
set<char> diffset;
for(int i=0;i<s.length();i++)
{
if(s[i]!=' ')
{
countn++;
diffset.insert(s[i]);
}
}
for(set<char>::iterator it=diffset.begin();it!=diffset.end();it++)
{
thisnum = count(s.begin(),s.end(),*it);
thischar = *it;
if(thisnum>maxnum)
{
maxnum=thisnum;
maxchar=thischar;
}
}
maxnum = maxnum*1.0/countn;
return maxnum;
}
int main()
{
string s;
getline(cin,s);
char maxchar = 'a';
double res = maxratio(s,maxchar);
printf("%c %.2lf\n",maxchar,res);
return 0;
}