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 geogles at 2012-12-27 21:25:31 on Problem 2562
#include<stdio.h>
#include<string.h>
int main()
{
	char m[12];
	char n[12];
	char f[12];
	int a,b,s,p,t;
	while(scanf("%s %s",m,n)!=EOF)
	{
		if(strcmp(m,"0")==0&&strcmp(n,"0")==0)
			break;
		a=strlen(m);
		b=strlen(n);
		s=0;
		if(a<b)
		{
			strcpy(f,m);
			strcpy(m,n);
			strcpy(n,f);
			t=a;
			a=b;
			b=t;
		}
		while(a>=0&&b>=0)
		{
			a--;
			b--;
			if((m[a]+n[b]-96)>=10)
			{
				s++;
				m[a-1]++;
				if(m[a-1]-48>=10)
				{
					p=a-1;
					while(m[p]-48>=10)
					{
						s++;
						m[p]=m[p]-10;
						m[p-1]++;
						p=p-1;
					}
				}
				
				
			}
		}
		if(s==0)
			printf("No carry operation.\n");
		else
			if(s==1)
				printf("1 carry operation.\n");
			else
				printf("%d carry operations.\n",s);
	}
	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