close

單用 int是無法解決問題的

因為測資最大可以到4294967296

超過INT_MAX 2147483647

網址:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=996

--------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    long long int a, b;

    while(scanf("%lld%lld", &a, &b) == 2)
        printf("%lld\n", (a - b) < 0 ? -(a - b) : a - b);

    return 0;
}
 

 

-2017-05-22-----------------------------------------------------------------------

import java.util.*;
public class main{
    public static void main(String[] args) {
        try{
            long a,b;
            Scanner in=new Scanner(System.in);
            while(in.hasNextLong()){
                a=in.nextLong();
                b=in.nextLong();
                System.out.println("" + Math.abs(a-b));
            }
            in.close();
        }catch(Exception e){
            System.out.println("Input error!");
        }
    }
};
 

arrow
arrow
    全站熱搜

    awesq123 發表在 痞客邦 留言(0) 人氣()