10055 - Hashmat the Brave Warrior

Moderator: Board moderators

zyxw
New poster
Posts: 24
Joined: Sat Mar 22, 2008 5:49 am
Location: Chennai
Contact:

Re: 10055 - Hashmat the Brave Warrior

Thanks once again mf
I am not totally useless, because I can still be used as a bad example

metalcarryon
New poster
Posts: 2
Joined: Mon Feb 09, 2009 7:41 pm

why wa?

why WA?

Code: Select all

``````#include<stdio.h>

int main()
{

double a,b,c;

while(scanf("%lf %lf" ,&a ,&b)==2)
{

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

}
return 0;
}
``````
it returns 4294967296 on 4294967296 0 and vice-versa..
thanks!

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

Re: 10055 - Hashmat the Brave Warrior

what will happen if a is equal to b?

I hope u better use long long.
try_try_try_try_&&&_try@try.com
This may be the address of success.

asif_khan_ak_07
New poster
Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

cannot the understand the mistake

here is the code I wrote for problem 10055-Hasmat he brave warrior

#include<stdio.h>

int main()
{
int a,b,c;
while((scanf("%d %d",&a,&b)==2))
{

c=b-a;

if(c>0)
printf("%d\n",c);

else
printf("%d\n",-c);
}

return 0;

}

the sample input i provided yielded correct results. But when i sent the solution to Online Judge the reply was wrong answer. Is there any problem in the code? This is the first problem i tried sending to online judge. please help me.

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: cannot the understand the mistake

Your program doesn't work, for example, for this input:

Code: Select all

``4294967296 0``

asif_khan_ak_07
New poster
Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

Re: cannot the understand the mistake

which data type should i use?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: cannot the understand the mistake

long long or double would work fine.

asif_khan_ak_07
New poster
Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

Re: cannot the understand the mistake

I used double and wrote the following code

#include<iostream.h>

int main()
{
double a,b,c;
while(cin>>a>>b)
{

c=a-b;

if(c>0)
cout<<c<<"\n";

else
cout<<-c<<"\n";

}

return 0;

}

but still the verdict from online judge is wrong answer

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: cannot the understand the mistake

When a=b, your program now prints "-0".

And you shouldn't use iostream.h - it's been obsolete for many, many years. Replace it with:

Code: Select all

``````#include <iostream>
using namespace std;``````

mhn
New poster
Posts: 4
Joined: Mon Jun 22, 2009 7:05 am

Re: 10055 - Hashmat the Brave Warrior

m a beginner in acm..this is the first problem i m trying to solve ..nd having a lot of difficulties in understanding..watz wrong in my code..can anyone help me??
here's my code:

#include<stdio.h>

void main()
{
long long int i,j;

while(scanf("%lld %lld",&i,&j)==2)
{
if(i<j) printf("%lld\n",j-i);
else printf("%lld\n",i-j);

}

}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 10055 - Hashmat the Brave Warrior

Don't mutilate English words! That's just rude. And use [ code] [/code] tags to post code, or else it looks ugly.

main() must return 'int'. And this int should be 0.

If your compiler thinks "void main()" is okay, then you should really consider dumping it and get yourself a real compiler. For example, gcc (its windows ports are cygwin and mingw)

joshua.bender
New poster
Posts: 2
Joined: Thu Sep 03, 2009 2:17 am

Re: 10055 - Hashmat the Brave Warrior

Can anybody help me what is wrong? i got the Wrong answer from the judge.

Code: Select all

``````import java.util.*;

public class Main {

public static void main(String args[]) {
long x, y;
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
Scanner scan2 = new Scanner(line);
scan2.useDelimiter(" ");
x = scan2.nextLong();
y = scan2.nextLong();
System.out.println((int) Math.abs(y - x));
}
}``````

Chaseph
New poster
Posts: 1
Joined: Mon Nov 16, 2009 9:27 am

Hashmat Warrior

Can someone tell me why my code is getting a wrong answer please. I've been having so much trouble with this being my first problem I just need a nudge to get me off the ground.

Code: Select all

``````import java.util.*;
import java.io.*;

class Main
{
public static void main(String[] args) throws IOException
{
while (true)
{
if (line == null) break;

StringTokenizer tokenizer = new StringTokenizer(line);
long num1 = Long.parseLong(tokenizer.nextToken());
long num2 = Long.parseLong(tokenizer.nextToken());

System.out.println(num2 - num1);
}
}
}``````

pooanaji
New poster
Posts: 1
Joined: Thu May 06, 2010 8:33 pm
Location: India

Re: 10055 - Hashmat the Brave Warrior

Hi,
I solved the problem using cin and cout. The running time was 0.340. What can i do to improve my running time? Any ideas?

Cheers,
Pooja

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10055 - Hashmat the Brave Warrior

use scanf() and printf()