• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

POJ-1047 Round and Round We Go

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
Round and Round We Go
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 10483   Accepted: 4802

Description

A cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the number after the last digit to "wrap around"back to the first digit, the sequence of digits in both numbers will be the same, though they may start at different positions.For example, the number 142857 is cyclic, as illustrated by the following table:
142857 *1 = 142857
142857 *2 = 285714
142857 *3 = 428571
142857 *4 = 571428
142857 *5 = 714285
142857 *6 = 857142

Input

Write a program which will determine whether or not numbers are cyclic. The input file is a list of integers from 2 to 60 digits in length. (Note that preceding zeros should not be removed, they are considered part of the number and count in determining n. Thus, "01"is a two-digit number, distinct from "1" which is a one-digit number.)

Output

For each input integer, write a line in the output indicating whether or not it is cyclic.

Sample Input

142857
142856
142858
01
0588235294117647

Sample Output

142857 is cyclic
142856 is not cyclic
142858 is not cyclic
01 is not cyclic
0588235294117647 is cyclic

 1 /* 
 2    功能Function Description:     POJ-1047 大数乘法 + 匹配 
 3    开发环境Environment:          DEV C++ 4.9.9.1
 4    技术特点Technique:
 5    版本Version:
 6    作者Author:                   可笑痴狂
 7    日期Date:                      20120803
 8    备注Notes:
 9 */
10 #include<stdio.h>
11 #include<string.h>
12 int len;
13 
14 int mult(int *num,int *temp,int n) //num中的数与n相乘存到temp中,如果结果位数大于num则返回0,否则返回1
15 {
16     int i,t=0;
17     for(i=0;i<len;++i)
18     {
19         t=num[i]*n+t;
20         temp[i]=t%10;
21         t/=10;
22     }
23     if(t)
24         return 0;
25     return 1;
26 }
27 
28 int Judge(int *num,int *temp)    //判断是否匹配
29 {
30     int i,j,k;
31     for(i=0;i<len;++i)
32     {
33         k=0;
34         if(temp[i]==num[0])
35         {
36             j=i;
37             while(k<len&&num[++k]==temp[(++j)%len]);
38             if(k==len)
39                 return 1;   //说明可以匹配
40         }
41     }
42     return 0;
43 }
44 
45 int main()
46 {
47     char s[65];
48     int num[65];
49     int temp[65];
50     int i,j,flag;
51     while(gets(s))
52     {
53         flag=1;
54         len=strlen(s);
55         memset(num,0,sizeof(num));
56         for(i=len-1,j=0;i>=0;--i)
57             num[j++]=s[i]-'0';
58         for(i=2;i<=len;++i)
59         {
60             memset(temp,0,sizeof(temp));
61             if(mult(num,temp,i))    
62             {
63                 if(Judge(num,temp)==0)
64                 {
65                     printf("%s is not cyclic\n",s);
66                     flag=0;
67                     break;
68                 }
69             }
70             else //相乘的结果位数增多肯定不满足,直接跳出
71             {
72                 printf("%s is not cyclic\n",s);
73                 flag=0;
74                 break;
75             }
76 
77         }
78         if(flag)
79             printf("%s is cyclic\n",s);
80     }
81     return 0;
82 }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
go语言学习-函数发布时间:2022-07-10
下一篇:
Go结构体嵌套发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap