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 fanhqme at 2009-02-21 15:39:43 on Problem 2602
接近超时......
#include <cstdio>
using namespace std;
int getdigit(){int a;while (a=getchar())if (a>='0' && a<='9')return a-'0';}
int main()
{
    int before9,nine,N,a,b;
    scanf("%d",&N);
    before9=nine=0;
    for (int i=0;i<N;i++){
        a=getdigit();b=getdigit();
        if (a+b>=10){
           putchar(before9+'1');
           for (int i=0;i<nine;i++)putchar('0');
           nine=0;
           before9=a+b-10;
        }
        else if (a+b<9){
             if (i>nine)putchar(before9+'0');
             for (int i=0;i<nine;i++)putchar('9');
             nine=0;
             before9=a+b;
        }else nine++;
    }
    if (N>nine)putchar(before9+'0');
    for (int i=0;i<nine;i++)putchar('9');
    putchar(10);
    getchar();getchar();
    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