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

我开150跟300就过了

Posted by Belldandy at 2011-12-05 08:20:36 on Problem 1503
In Reply To:开数组的,数组要开到1000.。。才过,再也不信题目给的条件了 Posted by:sw9416 at 2010-05-04 17:38:28
Source Code

Problem: 1503		User: Belldandy
Memory: 164K		Time: 0MS
Language: C		Result: Accepted
Source Code
#include<stdio.h>
#include<string.h>
#define MAX 300
#define max 150
int main()
{
	int i=0,len=0,c=0;
	int a[max]={0},ans[MAX]={0};
	char temp[max]={0};
	while(scanf("%s",temp)&&strcmp(temp,"0"))
	{
		for(i=0;temp[i];i++)
		{
			a[i]=temp[i]-'0';
		}
		len=i;
		for(i=0,c=0;i<len;i++)
		{
			ans[MAX-1-i]+=a[len-1-i]+c;
			if(ans[MAX-1-i]>9)
			{
				ans[MAX-1-i]-=10;
				c=1;
			}
			else
			{
				c=0;
			}
		}
		if(c)
		{
			ans[MAX-1-i]+=1;
			c=0;
		}
	}
	for(i=0;i<MAX;i++)
	{
		if(ans[i])
		{
			break;
		}
	}
	for(;i<MAX;i++)
	{
		printf("%d",ans[i]);
	}
	printf("\n");
}

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