博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ Round and Round We Go
阅读量:6153 次
发布时间:2019-06-21

本文共 2167 字,大约阅读时间需要 7 分钟。

Round and Round We Go

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 1   Accepted Submission(s) : 1
Problem 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
 
Source
PKU
 
 
 
#include
#include
#include
using namespace std;char str[100],s[100];int len;void Mul(int num,int a[],char s[]){ int tmp=0,b[100]; for(int i=0;i
%s \n",s);}int isOk(char s1[],char s2[]){ char s[200]; strcpy(s,s1); strcat(s,s1); if(strstr(s,s2)!=NULL) //这个strstr函数挺好用 return 1; return 0;}int main(){ //freopen("input.txt","r",stdin); int a[100]; while(~scanf("%s",str)){ len=strlen(str); int i,j; for(i=len-1,j=0;i>=0;i--) a[j++]=str[i]-'0'; for(i=2;i<=len;i++){ Mul(i,a,s); if(!isOk(str,s)) break; } if(i>len) printf("%s is cyclic\n",str); else printf("%s is not cyclic\n",str); } return 0;}

 

转载地址:http://lfwfa.baihongyu.com/

你可能感兴趣的文章
USACO 土地购买
查看>>
【原创】远景能源面试--一面
查看>>
B1010.一元多项式求导(25)
查看>>
10、程序员和编译器之间的关系
查看>>
配置 RAILS FOR JRUBY1.7.4
查看>>
AndroidStudio中导入SlidingMenu报错解决方案
查看>>
修改GRUB2背景图片
查看>>
Ajax异步
查看>>
好记性不如烂笔杆-android学习笔记<十六> switcher和gallery
查看>>
JAVA GC
查看>>
3springboot:springboot配置文件(外部配置加载顺序、自动配置原理,@Conditional)
查看>>
前端第七天
查看>>
图解SSH原理及两种登录方法
查看>>
【总结整理】JQuery基础学习---样式篇
查看>>
查询个人站点的文章、分类和标签查询
查看>>
基础知识:数字、字符串、列表 的类型及内置方法
查看>>
JSP的隐式对象
查看>>
JS图片跟着鼠标跑效果
查看>>
[SCOI2005][BZOJ 1084]最大子矩阵
查看>>
学习笔记之Data Visualization
查看>>