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

纪念一下...

Posted by gripleaf at 2011-09-13 19:20:42 on Problem 1047 and last updated at 2011-09-13 19:23:48
第一次用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:
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