P1598 vertical histogram

Keywords: PHP

Input format:

 

Four lines of characters, consisting of uppercase letters, with no more than 100 characters per line

 

Output format:

 

It is composed of several lines, the first line is composed of spaces and asterisks, and the last line is composed of spaces and letters. Do not print unnecessary extra spaces at the end of any line. Do not print any blank lines.

I've been wrong about this many times.

The code is as follows

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int main() {
 5     string a, b, c, d;
 6     char wod[27];
 7     for (int i = 0; i<27; i++) {
 8         wod[i] = 0;
 9     }
10     getline(cin, a);
11     getline(cin, b);
12     getline(cin, c);
13     getline(cin, d);
14     for (int i = 0; a[i]; i++) {
15         if (a[i] <= 'Z' && a[i] >= 'A') {
16             wod[a[i]-'A'] ++;
17         }
18     }
19     for (int i = 0; b[i]; i++) {
20         if (b[i] <= 'Z' && b[i] >= 'A') {
21             wod[b[i]- 'A'] ++;
22         }
23     }
24     for (int i = 0; c[i]; i++) {
25         if (c[i] <= 'Z' && c[i] >= 'A') {
26             wod[c[i]- 'A'] ++;
27         }
28     }
29     for (int i = 0; d[i]; i++) {
30         if (d[i] <= 'Z' && d[i] >= 'A') {
31             wod[d[i]- 'A'] ++;
32         }
33     }
34 
35     int f = 0, sum = 0, tem = 0;
36     for (int k = 0; k < 26; k++) {
37         if (f++ == 0) {
38             continue;
39         }
40         else {
41             if (wod[k] > wod[k - 1]) {
42                 tem = wod[k];
43                 if (tem > sum) {
44                     sum = tem;
45                 }
46             }
47         }
48     }
49     tem = sum - 1;
50     for (int p = 0; p < sum; p++) {
51         for (int k = 0; k < 26; k++) {
52             if (wod[k] - tem > 0) {
53                 cout << "*";
54                 int x = 0;
55                 for (int p = k + 1; p < 26; p++) {
56                     if (wod[p] - tem > 0) {
57                         x++;
58                         break;
59                     }
60                 }
61                 if (x == 0) {
62                     break;
63                 }
64             }
65             else {
66                 cout << " ";
67             }
68             cout << " ";
69         }
70         tem--;
71         cout << endl;
72     }
73     cout << "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
74     return 0;
75 }

So far, I don't know what 36 behaviors can't be.

Posted by bradlybrown on Sat, 02 Nov 2019 10:00:52 -0700