Page 8 of 12

Re: 10055 - Hashmat the Brave Warrior

Posted: Mon Jul 07, 2008 7:52 pm
by zyxw
Thanks once again mf :)
I'll follow them...

why wa?

Posted: Mon Feb 09, 2009 7:48 pm
by metalcarryon
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.. :roll:
thanks!

Re: 10055 - Hashmat the Brave Warrior

Posted: Tue Feb 10, 2009 7:25 am
by Obaida
what will happen if a is equal to b?

I hope u better use long long. :)

cannot the understand the mistake

Posted: Fri Apr 17, 2009 8:30 am
by asif_khan_ak_07
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. :cry:

Re: cannot the understand the mistake

Posted: Fri Apr 17, 2009 3:55 pm
by mf
Your program doesn't work, for example, for this input:

Code: Select all

4294967296 0

Re: cannot the understand the mistake

Posted: Fri Apr 17, 2009 8:30 pm
by asif_khan_ak_07
which data type should i use?

Re: cannot the understand the mistake

Posted: Fri Apr 17, 2009 9:08 pm
by mf
long long or double would work fine.

Re: cannot the understand the mistake

Posted: Sat Apr 18, 2009 6:35 pm
by asif_khan_ak_07
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

Re: cannot the understand the mistake

Posted: Sat Apr 18, 2009 8:31 pm
by mf
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;

Re: 10055 - Hashmat the Brave Warrior

Posted: Mon Jun 22, 2009 9:29 am
by mhn
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);



}


}

Re: 10055 - Hashmat the Brave Warrior

Posted: Tue Jun 23, 2009 8:32 am
by mf
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)

Re: 10055 - Hashmat the Brave Warrior

Posted: Thu Sep 03, 2009 2:34 am
by joshua.bender
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));
    }
}

Hashmat Warrior

Posted: Mon Nov 16, 2009 9:29 am
by Chaseph
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
  {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    while (true)
    {
      String line = reader.readLine();
      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);
    }
  }
}

Re: 10055 - Hashmat the Brave Warrior

Posted: Thu May 06, 2010 9:59 pm
by pooanaji
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

Re: 10055 - Hashmat the Brave Warrior

Posted: Fri May 07, 2010 2:02 pm
by sohel
use scanf() and printf()