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

和1001差不多

Posted by cyforever at 2010-08-23 09:42:30 on Problem 1047
去掉优化就对了。所有1。。。n都要运算,不能满足了就break;
如111111111 is cyclic
1111111111 is not cyclic

#include <iostream>
#include <string.h>
#include <cmath>

using namespace std;

int main()
{
  char num[61];
  int cyc[61],bt[61],p[61];
  int i,j,k,s,len,m;
  bool fl;
  while(scanf("%s",num)!=EOF)
{
  m=0;
  len=strlen(num);
  for(i=0;i<len;i++)
  {
      cyc[i]=num[i]-'0';
      bt[i]=cyc[i];
      p[i]=bt[i];
  }
  for(i=0;i<len;i++)
  {

      for(j=1;j<=len;j++)
      {
          fl=false;
          for(k=0;k<len;k++)
          p[k]=p[k]*j;
          for(k=len-1;k>0;k--)
          {
              p[k-1]+=p[k]/10;
              p[k]=p[k]%10;
              if(p[k]!=cyc[k]) {fl=true;break;}
          }
          if(p[0]>=10) {m=-1;break;}
          if(p[0]<10&&k==0&&fl==false)
          {
           m++;
          }
          for(k=0;k<len;k++)
          p[k]=bt[k];
      }
      if(p[0]>=10) break;
      s=cyc[len-1];
      for(k=len-2;k>=0;k--)
      cyc[k+1]=cyc[k];
      cyc[0]=s;
  }
  for(i=0;i<len;i++)
  printf("%d",bt[i]);
  if(m==len) printf(" is cyclic\n");
  else printf(" is not cyclic\n");
}
}

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