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 qq975364735 at 2009-09-28 10:37:50 on Problem 1047
#include<iostream>
#include<cstdlib>
using namespace std;
int a1[100],b[100],c[100],la;
char a[100];
int cmp(const void *l1,const void *l2)
{
    return *(int *)(l1)-*(int *)(l2);
}
int Compare()
{
    int i;
    for(i=0;i<la;i++)
        if(b[i]!=c[i])
            return 0;
    return 1;
}
int main()
{
    int n,i,k,g;
    while(cin>>a)
    {
        la=strlen(a);
        for(i=0;i<la;i++)
            a1[i]=a[la-i-1]-'0';
       
         for(i=0;i<la;i++)
              b[i]=a1[i]; 
        
        
        qsort(b,la,sizeof(int),cmp);

       
        g=0;
        for(k=1;k<=la;k++)
        {
            for(i=0;i<la;i++)
              c[i]=a1[i];
               for(i=0;i<la;i++)
                c[i]*=k;
            
            for(i=0;i<la;i++)
             {
                c[i+1]+=c[i]/10;
                 c[i]%=10;   
            }  
            qsort(c,la,sizeof(int),cmp);

                
                if(Compare()==0)
                {
                    g=1;
                    break;
                }
        }
        if(g==0)
            cout<<a<<" is cyclic"<<endl;
        else
            cout<<a<<" is not cyclic"<<endl;
    }
}
请大家帮我看看有没有数学方法可以证明我的答案也是对的?谢谢了!

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