## 10055 - Hashmat the Brave Warrior

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

HenryGale
New poster
Posts: 1
Joined: Tue Dec 13, 2011 8:16 am

### Re: 10055 Getting TLE

Same thing happened to me, so I had to substitute Scanner by a more efficient input method.
Also you may find this discussion interesting and useful. (Warning! It does contain multiple solutions to the 10055 problem.)

Khaldu
New poster
Posts: 2
Joined: Wed Mar 21, 2012 3:54 pm

### Re: 10055 - Hashmat the Brave Warrior

Why i getting time limit exceeded??? i use integer,,long,,long long all data types....
#include<stdio.h>
int main()
{
long long a,b,c;
for(;;)
{
scanf("%lld %lld",&a,&b);

if(a<b)
{ c=b-a;
printf("%lld\n",c);
}
if(a>b)
{ c=a-b;
printf("%lld\n",a-b);
}

}
return 0;

}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10055 - Hashmat the Brave Warrior

You don't have an exit condition. The loop will run forever waiting on more input from scanf.
Check input and AC output for thousands of problems on uDebug!

New poster
Posts: 1
Joined: Mon Apr 02, 2012 1:05 pm

### Re: 10055 - Hashmat the Brave Warrior

Why does this simply problem take 2.2s in java and take only 0.06s in ANSI C? I don't understand..

Code: Select all

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long a, b;

while (in.hasNextLong()) {
a = in.nextLong();
b = in.nextLong();
if (b > a)
System.out.println(b-a);
else
System.out.println(a-b);
}
}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10055 - Hashmat the Brave Warrior

JAVA is slower than C.
Check input and AC output for thousands of problems on uDebug!

cse.mehedi
New poster
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10055 Getting TLE

use Scanner cin = new Scanner(System.in);
you will get AC.

renatov
New poster
Posts: 20
Joined: Fri Sep 21, 2012 6:33 am

### Re: 10055 - Hashmat the Brave Warrior

Hey guys, I'm receiving a "Wrong Answer" when I submit, but the program is running just fine in Code Blocks (WinXP). I can even input 2^32 (4294967296) and everything still works. Could someone please help?

Code: Select all

accepted;

ps: just use "long long".
Last edited by renatov on Sun Sep 30, 2012 3:46 am, edited 2 times in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10055 - Hashmat the Brave Warrior

Use long long.
Check input and AC output for thousands of problems on uDebug!

renatov
New poster
Posts: 20
Joined: Fri Sep 21, 2012 6:33 am

### Re: 10055 - Hashmat the Brave Warrior

brianfry713 wrote:Use long long.
I changed to long long and it doesn't work either, although it works perfectly in my computer. Could somebody help me, please? Here is the code:

Code: Select all

#include <stdio.h>

int main()
{
long long int lldMenor;
long long int lldMaior;

while( scanf("%lld %lld", &lldMenor, &lldMaior) != EOF )
printf("%lld\n", lldMaior - lldMenor);

return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10055 - Hashmat the Brave Warrior

Print the absolute value of the difference.
Check input and AC output for thousands of problems on uDebug!

renatov
New poster
Posts: 20
Joined: Fri Sep 21, 2012 6:33 am

### Re: 10055 - Hashmat the Brave Warrior

It's working now, thanks!

ps: %lld didn't work on Windows (I had to use %I64d to test), but it worked for UVA's gcc.

Scorvus
New poster
Posts: 4
Joined: Sun Apr 21, 2013 8:19 pm

### Re: 10055 - Hashmat the Brave Warrior

what's wrong with my code? i got WA with this

Code: Select all

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10055 - Hashmat the Brave Warrior

Your code doesn't print anything.

Instead try something like:
while(scanf("%lld %lld",&h,&e) == 2) {
Check input and AC output for thousands of problems on uDebug!

Scorvus
New poster
Posts: 4
Joined: Sun Apr 21, 2013 8:19 pm

### Re: 10055 - Hashmat the Brave Warrior

what this line do?

while(scanf("%lld %lld",&h,&e) == 2) {

i'm sorry, i'm new with this thing.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10055 - Hashmat the Brave Warrior

http://www.cplusplus.com/reference/cstdio/EOF/