码迷,mamicode.com
首页 > 其他好文 > 详细

Hdu 5050 Divided Land

时间:2015-08-15 16:20:04      阅读:121      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!