唉 四个TLE!!!咋改呦

P1598 垂直柱状图

读入建议用getline
by tribool4_in @ 2021-03-05 19:41:45


另外样例就TLE了
by tribool4_in @ 2021-03-05 19:43:21


@[刘奶奶喝水呢](/user/342874) ```cpp #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; int main() { int num[26] = { 0 }; int l, maxn = 0; char s; string str; for (int i = 0; i < 4; i++) { getline(cin, str); for (int j = 0; j < str.size(); j++) { if (isupper(str[j])) { num[str[j] - 'A']++; } } } for (int i = 0; i < 26; i++) { maxn = max(maxn, num[i]); } for (int i = maxn; i > 0; i--) { for (int j = 0; j < 26; j++) { if (num[j] >= i) { if (j == 25) { cout << "*"; } else { cout << "* "; } } else { if (j == 25) { cout << " "; } else { cout << " "; } } } cout << endl; } for (int i = 0; i < 26; i++) { cout << (char)(i + 'A') << " "; } return 0; } ```
by tribool4_in @ 2021-03-05 19:46:33


@[wangwls](/user/341650) 太感谢了!
by 刘奶奶喝水呢 @ 2021-03-17 19:08:54


```c #include<iostream> #include<string> using namespace std; int al[28]; int main() { string a,b; int m=-1; getline(cin,a); for(int i=1;i<=3;i++) { getline(cin,b); a+=b; b=" "; } for(int i=0;i<a.size();i++) { if(a[i]>='A'&&a[i]<='Z') { al[a[i]-'A']++; } else continue; } for(int i=0;i<26;i++) { if(al[i]>m){m=al[i];} } for(int i=m;i>=1;i--) { for(int j=0;j<26;j++) { if(al[j]>=i) { cout<<"*"; } else {cout<<" ";} cout<<" "; } cout<<endl; } 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"; return 0; } ``` 也可以啊??
by nick_zha @ 2021-04-21 17:37:41


|