-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.cpp
129 lines (99 loc) · 2.25 KB
/
article.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
ifstream fin("article.in");
ofstream fout("article.out");
struct ch
{
char c;
int _count;
bool operator<(const ch &temp) const
{
return _count < temp._count;
}
};
int main()
{
long long total = 0;
vector<int> a(95, 0);
fout << fixed << setprecision(4);
while (true)
{
string in = "";
getline(fin, in);
if (fin.eof() == true)
{
break;
}
int size = in.size();
for (int i = 0; i <= size - 1; ++i)
{
for (char c = ' '; c <= '~'; ++c)
{
if (in[i] == c)
{
++a[c - ' '];
break;
}
}
}
total += size;
}
int _max = 0;
vector<string> out;
for (int i = 0; i <= 94; ++i)
{
char c = ' ' + i;
string temp = "";
temp.push_back(c);
for (int j = 1; j <= a[i]; ++j)
{
temp += '|';
}
_max = max(_max, a[i]);
out.push_back(temp);
}
for (int i = 0; i <= 94; ++i)
{
for (int c = 1; c <= _max - a[i]; ++c)
{
out[i].push_back(' ');
}
}
for (int j = _max - 1; j >= 0; --j)
{
for (int i = 0; i <= 94; ++i)
{
fout << out[i][j];
}
fout << '\n';
}
fout << '\n';
fout << "total chars: " << total << '\n';
double _total = (double)total;
vector<ch> list;
for (int i = 0; i <= 94; ++i)
{
char c = ' ' + i, k = 37;
double m = (double)a[i];
fout << c << ' ' << setw(10) << a[i] << setw(15) << m / _total * 100.0 << k << '\n';
ch temp{c, a[i]};
list.push_back(temp);
}
fout << '\n';
sort(list.begin(), list.end());
for (int i = 94; i >= 0; --i)
{
fout << list[i].c;
}
fout << '\n';
return 0;
}