首页 > ACM题库 > HDU-杭电 > HDU 1212 Big Number-高精度-[解题报告] java
2013
12-04

HDU 1212 Big Number-高精度-[解题报告] java

Big Number

问题描述 :

As we know, Big Number is always troublesome. But it’s really important in our ACM. And today, your task is to write a program to calculate A mod B.

To make the problem easier, I promise that B will be smaller than 100000.

Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.

输入:

The input contains several test cases. Each test case consists of two positive integers A and B. The length of A will not exceed 1000, and B will be smaller than 100000. Process to the end of file.

输出:

For each test case, you have to ouput the result of A mod B.

样例输入:

2 3
12 7
152455856554521 3250

样例输出:

2
5
1521

题目大意:输入两个数字a,b。输出a%b

解题思路:大数取余

代码如下:

package com.njupt.bigInteger;

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

public class HDU_1212_1 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		BigInteger a,b,c;
		
		while(scanner.hasNextBigInteger()){
			a = scanner.nextBigInteger();
			b = scanner.nextBigInteger();
			c = a.mod(b);//返回a%b的结果,赋给c
			
			System.out.println(c);
		}
	}
}


  1. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  2. 其实国内大部分公司对算法都不够重视。特别是中小型公司老板根本都不懂技术,也不懂什么是算法,从而也不要求程序员懂什么算法,做程序从来不考虑性能问题,只要页面能显示出来就是好程序,这是国内的现状,很无奈。

  3. 博主您好,这是一个内容十分优秀的博客,而且界面也非常漂亮。但是为什么博客的响应速度这么慢,虽然博客的主机在国外,但是我开启VPN还是经常响应很久,再者打开某些页面经常会出现数据库连接出错的提示