10055 - Hashmat the Brave Warrior

Problem Link

Cara nak selesaikan problem ni cuma perlu tolak je nilainya. Trick dia kat sini cuma mungkin nilai yang dimasukkan lebih besar jadi kalau integer memang tak boleh la. Dalam solution saya gunakan BigInteger.

Solution :
import java.util.*;
import java.math.*;
public class uva10055 {
public static void main(String [] args) throws Exception {
Scanner scn = new Scanner(System.in);
while(scn.hasNextBigInteger()) {
BigInteger a = scn.nextBigInteger();
BigInteger b = scn.nextBigInteger();
int c = a.compareTo(b);
if(c==1 || c==0)
System.out.println(a.subtract(b));
else
System.out.println(b.subtract(a));
}
}
}

Share this

Related Posts

Previous
Next Post »