HDOJ Problem 1002 Java兑现
HDOJ Problem 1002 Java实现
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanf = new Scanner(System.in); while(scanf.hasNext()) { int n; int i=1,x=0; n=scanf.nextInt(); while(n--!=0) { if(x++!=0) System.out.println(); BigInteger a,b,sum; a=scanf.nextBigInteger(); b=scanf.nextBigInteger(); sum=a.add(b); System.out.println("Case"+" "+ i++ +":"); System.out.print(a+" "+"+"+" "+b+" "+"="+" "); System.out.println(sum); } } } }
很奇怪的是上面这个竟然AC了,可是感觉不怎么符合题意,下面的这个更符合些,但是没有提交成功。
package com.xtfggef.bigdata2; import java.math.BigInteger; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { while(true){ BigInteger a,b,c,d; int T = 0,N=1,K=1; Queue<BigInteger> queue = new LinkedList<BigInteger>(); Scanner in = new Scanner(System.in); T = in.nextInt(); if(T>=1&&T<=20){ Scanner in2 = new Scanner(System.in); while (N<=T) { a = in2.nextBigInteger(); b = in2.nextBigInteger(); queue.offer(a); queue.offer(b); N++; } while(K<=T){ c = queue.poll(); d = queue.poll(); System.out.println("Case "+K+":"); System.out.println(c+" + "+d+" = "+sum(c, d)); if(K<T){ System.out.println(); } K++; } } } } static BigInteger sum(BigInteger a ,BigInteger b){ return a.add(b); } }
- 3楼xiaoluo5013953774天前 20:24
- 0.0 我来see see啦 这些都是传说中的算法么?
- 2楼xiaoluo5013953774天前 12:59
- 0.0 一般要掌握哪些算法的实现呢?
- Re: zhangerqing4天前 18:00
- 回复xiaoluo501395377n算法的话,本科生不大可能做到很专的方面,主要就是写程序的思维,你可以看看那些面试题,想要练习的话,找个OJ,如杭州电子科技大的或者北大的,好多名牌大学都有OJ,在那个上面练习就行了,从简单到难的都有。
- 1楼zhangerqing4天前 12:13
- 呵呵!就是最简单的一些题啦!谈不上算法,开始的都是练输入输出。