Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

晒个代码,读到4次回车结束输入

Posted by odakyuusen at 2012-07-22 10:24:06 on Problem 2136
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	char ch;
	int maxn,cnt=0,t,alpha[26]={0};
	bool flag;
	while(true)
	{
		scanf("%c",&ch);
		if(ch=='\n')
		{
			cnt++;
			if(cnt==4)
				break;
			continue;
		}
		if(ch-'A'>=0  &&  ch-'A'<26)
		{
			t=int(ch-'A');
			alpha[t]++;
		}
	}
	maxn=0;
	for(int i=0;i<26;i++)
		maxn=max(alpha[i],maxn);
	cnt=maxn;
	while(cnt)
	{
		for(int i=0;i<26;i++)
		{
			if(i!=0)
				printf(" ");
			if(alpha[i]>=cnt)
				printf("*");
			else
				printf(" ");
		}
		printf("\n");
		cnt--;
	}
	for(int i=0;i<26;i++)
	{
		if(i!=0)
			printf(" ");
		ch='A'+i;
		printf("%c",ch);
	}
	printf("\n");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator