10055 - Hashmat the Brave Warrior
Moderator: Board moderators
Re: 10055 - Hashmat the Brave Warrior
Thanks once again mf
I'll follow them...
I'll follow them...
I am not totally useless, because I can still be used as a bad example
-
- New poster
- Posts: 2
- Joined: Mon Feb 09, 2009 7:41 pm
why wa?
why WA?
it returns 4294967296 on 4294967296 0 and vice-versa..
thanks!
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;
}
thanks!
Re: 10055 - Hashmat the Brave Warrior
what will happen if a is equal to b?
I hope u better use long long.
I hope u better use long long.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- 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.
#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.
Re: cannot the understand the mistake
Your program doesn't work, for example, for this input:
Code: Select all
4294967296 0
-
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Re: cannot the understand the mistake
which data type should i use?
Re: cannot the understand the mistake
long long or double would work fine.
-
- 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
#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
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:
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
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);
}
}
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
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)
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)
-
- 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));
}
}
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
{
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
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
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