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

有点像打印机 这是我的代码

Posted by 201101050424 at 2011-12-25 00:12:55 on Problem 1102
#include <stdio.h>
#include <string.h>
int main()
{
	int number,size;
	char yuan[10];
	int i;
	int j=0;
	int l;
	int m;
	int x;
	char a[200][200]; 
	int len;
	int o;
	int flag=0;
	scanf("%d %d",&size,&number);
	while(size!=0)
	{
		sprintf(yuan,"%d",number);
		len=strlen(yuan);
		j=0;
		for(l=0;l<(size+2)*len+len;)
		{
			if(yuan[j]=='2'||yuan[j]=='3'||yuan[j]=='5'||yuan[j]=='6'||yuan[j]=='7'||yuan[j]=='8'||yuan[j]=='9'||yuan[j]=='0')
			{
				a[0][l++]=' ';
				o=l-1;
				for(;l<=o+size;l++)
				{
					a[0][l]='-';
				}
				a[0][l++]=' ';
			}
			else if(yuan[j]=='1'||yuan[j]=='4')
			{
				a[0][l++]=' ';
				o=l-1;
				for(;l<=o+size;l++)
				{
					a[0][l]=' ';
				}
				a[0][l++]=' ';
			}
			a[0][l++]=' ';
			j++;
		}
		for(m=1;m<=size;m++)
		{	
			j=0;
			for(i=0;i<(size+2)*len+len;)
			{
				if(yuan[j]=='1'||yuan[j]=='2'||yuan[j]=='3'||yuan[j]=='7')
				{
					a[m][i++]=' ';
					o=i;
					for(;i<=size+o-1;i++)
					{
						a[m][i]=' ';
					}
					a[m][i++]='|';
				}
				else if(yuan[j]=='5'||yuan[j]=='6')
				{
					a[m][i++]='|';
					o=i;
					for(;i<=size+o-1;i++)
					{
						a[m][i]=' ';
					}
					a[m][i++]=' ';
				}
				else if(yuan[j]=='0'||yuan[j]=='4'||yuan[j]=='8'||yuan[j]=='9')
				{
					a[m][i++]='|';
					o=i;
					for(;i<=size+o-1;i++)
					{
						a[m][i]=' ';
					}
					a[m][i++]='|';
				}
				a[m][i++]=' ';
				j++;
			}
		}
		j=0;
		for(l=0;l<(size+2)*len+len;)
		{
			if(yuan[j]=='0'||yuan[j]=='1'||yuan[j]=='7')
			{
				a[size+1][l++]=' ';
				o=l-1;
				for(;l<=size+o;l++)
				{
					a[size+1][l]=' ';
				}
				a[size+1][l++]=' ';
			}
			else if(yuan[j]=='2'||yuan[j]=='3'||yuan[j]=='4'||yuan[j]=='5'||yuan[j]=='6'||yuan[j]=='9'||yuan[j]=='8')
			{
				a[size+1][l++]=' ';
				o=l-1;
				for(;l<=size+o;l++)
				{
					a[size+1][l]='-';
				}
				a[size+1][l++]=' ';
			}
			a[size+1][l++]=' ';
			j++;
		}
		for(m=size+2;m<=2*size+1;m++)
		{	
			j=0;
			for(i=0;i<(size+2)*len+len;)
			{
				if(yuan[j]=='1'||yuan[j]=='4'||yuan[j]=='3'||yuan[j]=='5'||yuan[j]=='7'||yuan[j]=='9')
				{
					a[m][i++]=' ';
					o=i-1;
					for(;i<=size+o;i++)
					{
						a[m][i]=' ';
					}
					a[m][i++]='|';
				}
				else if(yuan[j]=='2')
				{
					a[m][i++]='|';
					o=i-1;
					for(;i<=size+o;i++)
					{
						a[m][i]=' ';
					}
					a[m][i++]=' ';
				}
				else if(yuan[j]=='0'||yuan[j]=='6'||yuan[j]=='8')
				{
					a[m][i++]='|';
					o=i-1;
					for(;i<=size+o;i++)
					{
						a[m][i]=' ';
					}
					a[m][i++]='|';
				}
				a[m][i++]=' ';
				j++;
			}
		}
		j=0;
		for(l=0;l<(size+2)*len+len;)
		{
			if(yuan[j]=='4'||yuan[j]=='1'||yuan[j]=='7')
			{
				a[2*size+2][l++]=' ';
				o=l-1;
				for(;l<=size+o;l++)
				{
					a[2*size+2][l]=' ';
				}
				a[2*size+2][l++]=' ';
			}
			else if(yuan[j]=='0'||yuan[j]=='3'||yuan[j]=='2'||yuan[j]=='5'||yuan[j]=='6'||yuan[j]=='8'||yuan[j]=='9')
			{
				a[2*size+2][l++]=' ';
				o=l-1;
				for(;l<=size+o;l++)
				{
					a[2*size+2][l]='-';
				}
				a[2*size+2][l++]=' ';
			}
			a[2*size+2][l++]=' ';
			j++;
		}
		if(flag==0)
		{
			for(i=0;i<2*size+3;i++)
			{
				a[i][(size+2)*len+len-1]='\0';
				puts(a[i]);
			}
			flag=1;
		}
		else
		{
			printf("\n");
			for(i=0;i<2*size+3;i++)
			{
				a[i][(size+2)*len+len-1]='\0';
				puts(a[i]);
			}
		}
		scanf("%d %d",&size,&number);
	}
	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