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

汗,连goto都用上了呵呵

Posted by rpbear at 2009-11-21 22:54:03 on Problem 1519
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>

int main(){

    int n=0,length;
    char input[2500];
    memset(input,'0',2500);
    while(scanf("%s",input) && input[0]-'0'){
        int i=0;
        for(;i<strlen(input);i++)
            n += (input[i]-'0');
        int sum = 0;
label:  while(n>9 || n){
            sum += n%10;
            n /= 10;
        }
        if(sum > 9){
            n = sum;
            sum = 0;
            goto label;
        }

        printf("%d\n",sum!=0?sum:n);
        memset(input,'0',2500);
    }

	return EXIT_SUCCESS;
}

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