import java.math.BigInteger;
import java.util.Scanner;
public class Main {
private static int[] numbers =new int[10];;
private static int[] nn= new int[10];;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
for (int i=1;i<10;i++)
numbers[i]=0;
String str = scan.next();
for (char c : str.toCharArray()) {
numbers[c - '0']++;
}
BigInteger org = new BigInteger(str);
boolean cyclic = true;
BigInteger last = org;
for (int i = 1; i < str.length() && cyclic; i++) {
BigInteger nb = last.add(org);
for (int k=1;k<10;k++){
nn[k]=0;
}
String str2 = nb.toString();
for (char c : str2.toCharArray()) {
nn[c - '0']++;
}
if (str2.length() <= str.length()) {
for (int j = 1; j < 10; j++) {
if (numbers[j] != nn[j]) {
cyclic = false;
break;
}
}
} else {
cyclic = false;
}
last= nb;
}
if (cyclic)
System.out.println(str + " is cyclic");
else
System.out.println(str + " is not cyclic");
}
}
}
poj1047
最新推荐文章于 2017-05-02 18:57:39 发布