-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1521.cc
35 lines (30 loc) · 815 Bytes
/
1521.cc
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
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
while(true) {
string str;
cin >> str;
if(str == "END") break;
map<char,int> m;
for(int i = 0; i < str.size(); ++i)
m[str[i]]++;
vector<int> v;
for(map<char,int>::iterator it = m.begin(); it != m.end(); ++it)
v.push_back(it->second);
sort(v.begin(), v.end(), greater<int>());
int len = 1;
int sum = 0;
for(int i = 0; i < v.size(); ++i) {
sum += len * v[i];
if(i < (int)v.size()-2) ++len;
}
printf("%d %d %.1f\n", str.size()*8, sum, (double)str.size()*8/sum);
}
return 0;
}