-
Notifications
You must be signed in to change notification settings - Fork 34
/
10062.cpp
executable file
·57 lines (49 loc) · 960 Bytes
/
10062.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
/* Problem: Tell me the frequencies UVa 10062
Programmer: Md. Mahmud Ahsan
Compiled: Visual C++ 6.0
Date: 03-10-04
*/
#include <iostream>
#include <string>
using namespace std;
int getMax(int array[]);
int main(){
char str[1005];
int freq[150];
int i, j;
int size;
int c; // use for counting frequencies
int max;
int flag = 0;
while (cin.getline(str, sizeof(str)) && !cin.eof()){
size = strlen(str);
for (i = 32; i <= 127; i++){
c = 0;
for (j = 0; j < size; j++){
if (i == str[j])
++c;
}
freq[i] = c;
}
max = getMax(freq);
if (flag)
cout << endl;
flag = 1;
for (i = 1; i <= max; i++){
for (j = 127; j >= 32; --j){
if (i == freq[j])
cout << j << " " << freq[j] << endl;
}
}
}
return 0;
}
int getMax(int array[]){
int max = 0;
int i;
for (i = 32; i <= 127; i++){
if (max < array[i])
max = array[i];
}
return max;
}