• poj1047


    高精度,java做

    View Code
    import java.io.*;
    import java.util.*;
    import java.math.*;
    
    public class Main {
        
        public static boolean equal(String a, String b, int x)
        {
            int len = a.length();
            for (int i = 0; i < len; i++)
                if (a.charAt(i) != b.charAt((i + x) % len))
                    return false;
            return true;
        }
        
        public static boolean ok(String a, String b)
        {
            for (int i = b.length(); i < a.length(); i++)
                b = "0" + b;
            for (int i = 0; i < b.length(); i++)
                if (equal(a, b, i))
                    return true;
            return false;
        }
        
        public static void main(String[] args) throws FileNotFoundException
        {
    //        Scanner cin = new Scanner(new FileInputStream("t.txt"));
            Scanner cin = new Scanner(System.in);
            while (cin.hasNext())
            {
                String st = cin.next();
                BigInteger a = new BigInteger(st);
                BigInteger b;
                boolean cycle = true;
                int n = st.length();
                for (int i = 1; i <= n; i++)
                {
                    b = a.multiply(BigInteger.valueOf(i));
                    if (!ok(st, b.toString()))
                    {
                        cycle = false;
                        break;
                    }
                }
                if (cycle)
                    System.out.println(st + " is cyclic");
                else
                    System.out.println(st + " is not cyclic");
            }
        }
    }
  • 相关阅读:
    库函数文件操作
    系统文件操作函数
    time函数
    字符(串)输入输出函数
    select&epoll
    epoll
    select
    Apache 配置虚拟主机三种方式
    Apache VirtualHost配置
    Scrapy中用xpath/css爬取豆瓣电影Top250:解决403HTTP status code is not handled or not allowed
  • 原文地址:https://www.cnblogs.com/rainydays/p/2853533.html
Copyright © 2020-2023  润新知