输入格式:
四行字符,由大写字母组成,每行不超过100个字符
输出格式:
由若干行组成,前几行由空格和星号组成,最后一行则是由空格和字母组成的。在任何一行末尾不要打印不需要的多余空格。不要打印任何空行。
这个我错了好多次
代码如下
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 }
至今不知道36行为啥不能是wod[k]