求助,卡60分
查看原帖
求助,卡60分
202816
Ich_liebe_dich楼主2022/4/10 00:08

RT 这个是我写的第一个有分代码,没有去除任何多余空格,60分

#include<iostream>
#include<string>
using namespace std;
int main()
{
	char c;
	short a['Z']={0},i,j,maxn=0,cnt;
	string str;
	string::iterator si;
	for(i=1;i<=4;++i)
	{
		getline(cin,str);
		for(si=str.begin();si!=str.end();++si)
			++a[*si];
	}
	for(c='A';c!='Z';++c)
		maxn=max(maxn,a[c]);
	
	for(i=maxn;i>=1;--i)
	{
		for(c='A';c<='Z';++c)
			if(a[c]>=i)
				cout<<"* ";
			else
				cout<<"  ";
		cout<<'\n';
	}
	for(c='A';c<='Z';++c)
		cout<<c<<' ';
	return 0;
}

这个是加了去除空格功能,但是每行末尾都有空格的,也是60分

#include<iostream>
#include<string>
using namespace std;
int main()
{
	char c;
	short a['Z']={0},i,j,maxn=0,cnt;
	string str;
	string::iterator si;
	for(i=1;i<=4;++i)
	{
		getline(cin,str);
		for(si=str.begin();si!=str.end();++si)
			++a[*si];
	}
	for(c='A';c!='Z';++c)
		maxn=max(maxn,a[c]);
	
	for(i=maxn;i>=1;--i)
	{
		cnt=0;
		for(c='A';c<='Z';++c)
			if(a[c]>=i)
			{
				for(j=1;j<=cnt;++j)
					cout<<"  ";
				cout<<"* ";
				cnt=0;
			}
			else
				++cnt;
		cout<<'\n';
	}
	for(c='A';c<='Z';++c)
		cout<<c<<' ';
	return 0;
}

这个是已经把所有可能的多余的空格都去掉的代码,还是60分

#include<iostream>
#include<string>
using namespace std;
int main()
{
	char c;
	short a['Z']={0},i,j,maxn=0,cnt;
	string str;
	string::iterator si;
	for(i=1;i<=4;++i)
	{
		getline(cin,str);
		for(si=str.begin();si!=str.end();++si)
			++a[*si];
	}
	for(c='A';c!='Z';++c)
		maxn=max(maxn,a[c]);
	
	for(i=maxn;i>=1;--i)
	{
		cnt=0;
		if(a['A']>=i)
		{
			cout<<"*";
			cnt=0;
		}
		else
			cout<<' ';
		for(c='B';c<='Z';++c)
			if(a[c]>=i)
			{
				for(j=1;j<=cnt;++j)
					cout<<"  ";
				cout<<" *";
				cnt=0;
			}
			else
				++cnt;
		cout<<'\n';
	}
	cout<<'A';
	for(c='B';c<='Z';++c)
		cout<<' '<<c;
	return 0;
}

错误样例:

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM PROGRAM.
HELLO!

标解:

                            *
                            *
        *                   *
        *                   *     *   *
        *                   *     *   *
*       *     *             *     *   *
*       *     * *     * *   *     * * *
*       *   * * *     * *   * *   * * * *
*     * * * * * *     * * * * *   * * * *     * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
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

错误原因: Wrong Answer.wrong answer Too short on line 10.

2022/4/10 00:08
加载中...