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

超时 n次 !!!

Posted by 810974380 at 2009-08-09 14:21:48 on Problem 2602
开始用scanf printf   超时

改成getchar putchar  用gcc  提交  125 ms~    (附代码)



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,a[1000001];
int main()
{   int i,x,y;char s,t;
	scanf("%d",&n);
	getchar(); 
	for(i=0;i<n;i++)
	{
	 s=getchar();getchar();
	 t=getchar();getchar();
	 x=s-'0';y=t-'0';
	 a[i]=x+y;
	}
    for(i=n-1;i>=1;i--)
    if(a[i]>=10){a[i]=a[i]%10;a[i-1]++;}
	for(i=0;i<n;i++)
	{s=a[i]+'0';
	 putchar(s);
    }
    system("pause");
	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