首页 > 其他 > 详细

Hdu 5050 Divided Land

时间:2015-08-15 16:18:06      阅读:115      评论:0      收藏:0      [点我收藏+]

题目要求就是做求两个二进制数的gcd,如果是用java的话,这题很简单。但也可以用C++做,只能先给自己留下这个坑了,还在研究c++的做法。

import java.math.BigInteger;
import java.util.Scanner;

/**
 * Created by emerald on 8/14/15.
 *
 */
public class Main {

    public static void main(String []args) {
        Scanner in = new Scanner(System.in);
        BigInteger d1, d2;
        String line, str[], a, b;
        int T = in.nextInt(), Case = 0;
        in.nextLine();
        while(T!=0) {
            T --;
            line = in.nextLine();
            str = line.split(" ");
            System.out.print("Case #" + (++ Case) +": ");
            if(str[0].equals(str[1])) {
                System.out.println(str[0]);
                continue;
            }
            a = str[0];
            b = str[1];
            d1 = new BigInteger(a, 2);
            d2 = new BigInteger(b, 2);
            System.out.println((d1.gcd(d2)).toString(2));
        }
    }
}

 

Hdu 5050 Divided Land

原文:http://www.cnblogs.com/Emerald/p/4732444.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!