Saturday, July 13, 2013

Uva 10055 - Hashmat The Brave Warrior

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

Java code:

import java.util.Scanner;
public class HasmatThewBraveWarrior {
    public static void main(String[] args) {
        int a,b;
        Scanner in=new Scanner(System.in);
        while(in.hasNext())
        {
            long a =in.nextLong();
            long b =in.nextLong();
            if(a>b)
                System.out.println(a-b);
            else
                System.out.println(b-a);
        }
     
    }
}

C code:

#include<stdio.h>
int main()
{
 long long int a,b;
 while (scanf("%lld %lld",&a, &b)==2)
 {
  if (a>b)
   printf("%lld\n",a-b);
  else
   printf("%lld\n",b-a);
 }
 return 0;
}

C++ code:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
 long long a,b;
 while(cin>>a>>b)
  cout<<abs(a-b)<<endl;

 return 0;
}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home