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:000000 is not cyclic

Posted by snowfall at 2009-03-03 13:39:20 on Problem 1047
In Reply To:000000 is not cyclic Posted by:snowfall at 2009-03-03 13:37:21
#include<stdio.h>
#include<string.h>

#define N 61

char a[N],result[N];
int main()
{
    int flag,n;
    while(scanf(" %s",a+1)!=EOF)
    {
        int i;
        n=strlen(a+1);
        int temp=0;
        for(i=n;i>=1;i--)
        {
            result[i]= (temp+(a[i]-'0')*(n+1)) %10+'0';
            //printf("%c ",result[i]);
            temp=(temp+(a[i]-'0')*(n+1))/10;
        }
        flag=0;
        //printf("%s\n",result+1);
        for(i=1;i<=n;i++)
            if(result[i]!='9')
            {
                flag=1;
                break;
            }
        if(flag)
            printf("%s is not cyclic\n",a+1);
        else
            printf("%s is cyclic\n",a+1);
    }
    return 0;
}

这个代码AC了。
000000 is not cyclic
11111111 is cyclic
有点想不明白。。。

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