Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
纪念一下...第一次用java水过这题。。。而且还是1y。。。啧啧啧 其实想想,发现此题数据还是很弱的。。。在我的java中发现多个bug- -|| 附代码,望各位神牛能够出数据卡掉我的代码,zro orz : import java.util.*; import java.math.*; public class Main { static String str; public static boolean Judge(String st) { int i, j; int flag; char[] sst = st.toCharArray(); char[] sstr = str.toCharArray(); if (st.length() != str.length()) { return false; } for (i = 0; i < st.length(); i++) { flag = 1; for (j = 0; j < st.length(); j++) { if (sstr[j] != sst[(j + i) % st.length()]) { flag = 0; break; } } if (flag == 1) { return true; } } return false; } public static void main(String args[]) { Scanner cin = new Scanner(System.in); while (cin.hasNext()) { str = cin.next(); BigInteger s = new BigInteger(str); BigInteger t = new BigInteger("2"); int tt = 8; int flag = 0; while (tt-- > 0) { String st = s.multiply(t).toString(); if (Judge(st) == true) { flag = 1; break; } t = t.add(BigInteger.ONE); } if (flag == 1) { System.out.println(str + " is cyclic"); } else { System.out.println(str + " is not cyclic"); } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator