题目中有这么一句话:
在任何一行末尾不要打印不需要的多余空格。不要打印任何空行。
而传统的输出一般都长这样:
for(/*遍历*/){
cout<<"*"<<" ";
}
而这样输出,在行结尾也会有一个多余的空格。
根据评测机的机制,在行结尾的空格会自动省略掉,不会评测到,所以使用如上不正确的输出方法并不会判错,导致了很多答案与题面不符。
我认为正确的答案应该是类似这样的:
#include<iostream>
using namespace std;
int a[114514];
int main(){
char c;
int maxx=0;
//输入
while(cin>>c){
if(c>='A'&&c<='Z'){
a[c-'A'+1]++;
maxx=max(maxx,a[c-'A'+1]);
}
}
//第一行第一个
if(a[1]==maxx){
cout<<"*";
}
else cout<<" ";
//第一行其余
for(int i=2;i<=26;i++){
cout<<" ";
if(a[i]>=maxx) cout<<"*";
else cout<<" ";
}
maxx--;
//其余行
while(maxx){
//其余行第一个
cout<<"\n";
if(a[1]>=maxx){
cout<<"*";
}
else cout<<" ";
//其余行剩余
for(int i=2;i<=26;i++){
cout<<" ";
if(a[i]>=maxx) cout<<"*";
else cout<<" ";
}
maxx--;
}
cout<<"\nA 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;
}
so,请大佬们评价一下吧 awa