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 skogt at 2010-03-09 19:38:43 on Problem 2562
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100],b[100];
	int l1,l2;
	int i,j,t;
	int c[100],d[100],e[100];
	while(scanf("%s %s",a,b)==2)
	{
		int count=0;
		if(a[0]=='0'&&b[0]=='0')	break;
		l1=strlen(a);
		l2=strlen(b);
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));
		memset(e,0,sizeof(e));
		for(i=l1;i>=0;i--)
			c[i]=a[i]-'0';
		for(j=l2;j>=0;j--)
			d[i]=b[i]-'0';
		if(l1>l2)	t=l2;
		else t=l1;
		for(i=t-1;i>=0;i--)
		{
			e[i]+=d[i]+c[i];
			if(e[i]>=10)
			{
				e[i]-=10;
				e[i+1]++;
				count++;
			}
		}
		if(count==0)
			printf("No carry operation.\n");
		else if(count==1)
			printf("1 carry operation.\n");
		else
			printf("%d carry operation.",count);
	}

	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