20分,大佬帮帮我!

P1598 垂直柱状图

字符串里有空格,你这样输入只会读入前四个单词。请使用getline
by C20220215 @ 2023-03-09 19:52:08


```cpp #include <iostream> #include <string> //这里头文件改一下 using namespace std; int cnt[27]; string p[1000]; int main() { string a, b; getline(cin, a); getline(cin, b); a += b; getline(cin, b); a += b; getline(cin, b); a += b; for (int i = 0; i < a.length(); i++) { if (a[i] >= 'A' && a[i] <= 'Z') { cnt[a[i] - 'A' + 1] ++; } } int maxn = -1e9; for (int i = 1; i <= 26; i++) { maxn = max(maxn, cnt[i]); } for (int i = 1; i <= maxn; i++) { for (int j = 1; j <= 26; j++) { if (cnt[j] > 0) { p[i] += "*"; cnt[j] --; } else { p[i] += " "; } if (j != 26) { p[i] += " "; } } } for (int i = maxn; i >= 1; i--) { cout << p[i] << endl; } for (int i = 1; i <= 26; i++) { if (i != 26) cout << char(i + 'A' - 1) << " "; else cout << char(i + 'A' - 1); } return 0; } ```
by C20220215 @ 2023-03-09 19:55:06


|