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

Re:求:数据,打败我的程序(内附代码),谢谢各位朋友了!!

Posted by DieIng at 2008-06-29 05:48:47 on Problem 1503
In Reply To:求:数据,打败我的程序(内附代码),谢谢各位朋友了!! Posted by:wendachuan at 2008-03-04 16:13:52
> #include<stdio.h>
> #include<string.h>
> int main(void)
> {
> 	int ans[120];
> 	for(int i=0;i<120;i++)
> 	{
> 		ans[i]=0;
> 	}
> 	int flag=0;
> 	while(1)
> 	{
> 		char str[105];
> 		scanf("%s",&str);
> 		int len=strlen(str);
> 		if(!strcmp(str,"0"))
> 			break;
> 		flag++;
> 		i=119;
> 		for(int j=len-1;j>=0;j--,i--)
> 		{ 
> 			ans[i]+=(str[j]-'0');
> 			if(ans[i]>9)
> 			{
> 				ans[i]-=10;
> 				ans[i-1]++;
> 			}
> 		}
> 	}
> 	while(ans[i]>9&&flag!=0)
> 	{
> 		ans[i]-=10;
> 		ans[i-1]++;
> 		i--;
> 	}
> 	for(i=0;ans[i]==0;i++)
> 		;
>     while(i<120)
> 	{
> 		printf("%d",ans[i]);
> 		i++;
> 	}
> 	if(flag!=0)
> 	{
> 	    printf("\n");
> 	}
> 	return 0;
> }
> 
你的ans数组开小了。开大吧

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