10055 - Hashmat the Brave Warrior
Moderator: Board moderators
10055
hey!
*use simply double data type
* subtract the low value from the high value always.
Then u get AC
bye
*use simply double data type
* subtract the low value from the high value always.
Then u get AC
bye
Born to be a programmer!
10055 Hashmat the brave warrior ( How it could be wrong !! )
Hi all, I solve this problem and the judge say that something wrong and I can't get it help please
The problem : http://icpcres.ecs.baylor.edu/onlinejud ... roblem=996
My code :
#include<iostream>
using namespace std;
int main()
{
int x, y;
while(cin >> x >> y)
{
cout << y-x << endl;
}
return 0;
}
Thanks
The problem : http://icpcres.ecs.baylor.edu/onlinejud ... roblem=996
My code :
#include<iostream>
using namespace std;
int main()
{
int x, y;
while(cin >> x >> y)
{
cout << y-x << endl;
}
return 0;
}
Thanks
-
- New poster
- Posts: 10
- Joined: Mon Feb 25, 2008 8:22 pm
- Location: Dhaka, Bangladesh.
WHAT AM I DOING WRONG?????
Code: Select all
#include <iostream>
int main()
{
unsigned int a, s,temp;
while(scanf("%u%u",&a,&s)==2)
{
if(s<a)
{
temp=s;
s=a;
a=temp;
}
printf("%u\n",s-a);
}
return 0;
}
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
Re: 10055 - Hashmat the Brave Warrior
starrynight says
You can try putting this before the main function as global varibles and also selecting C++ compiler.
long long int num1 ,num2,answer;
It may help.
Help!! still GOT WA
int main()
{
long long int num1 ,num2,answer;
while(scanf("%lld %lld",&num1,&num2) != EOF)
{
if(num1 > num2)
{
answer = num1 - num2;
printf("%lld\n",answer);
}
else
{
answer = num2 - num1;
printf("%lld\n",answer);
}
}
return 0;
}
I wrote this in C!
why I still got a WA~?
thx!![]()
You can try putting this before the main function as global varibles and also selecting C++ compiler.
long long int num1 ,num2,answer;
Code: Select all
long long int num1 ,num2,answer;
int main()
{
while(scanf("%lld %lld",&num1,&num2) != EOF)
{
if(num1 > num2)
{
answer = num1 - num2;
printf("%lld\n",answer);
}
else
{
answer = num2 - num1;
printf("%lld\n",answer);
}
}
return 0;
}
10055 - RTE in JAVA (SOLVED)
I solved this problem long ago using C++ (which is my usual language).
I am a newbie in Java...
I wanted to use Java in UVa. So i chose a easy problem(10055) to start with.
But...
RUNTIME ERROR is the only verdict i'm getting
I don't think there is any error in algorithm![:wink:](./images/smilies/icon_wink.gif)
So i'm posting in Java forum.
What might be the mistake? Is my method of taking input wrong? If so, what is the correct way??
Here is the code: ( Works fine in my computer )
I am a newbie in Java...
I wanted to use Java in UVa. So i chose a easy problem(10055) to start with.
But...
![:o](./images/smilies/icon_eek.gif)
RUNTIME ERROR is the only verdict i'm getting
![:oops:](./images/smilies/icon_redface.gif)
I don't think there is any error in algorithm
![:wink:](./images/smilies/icon_wink.gif)
So i'm posting in Java forum.
What might be the mistake? Is my method of taking input wrong? If so, what is the correct way??
Here is the code: ( Works fine in my computer )
Code: Select all
Thanks to mf... Got AC...
I am not totally useless, because I can still be used as a bad example ![:P](./images/smilies/icon_razz.gif)
![:P](./images/smilies/icon_razz.gif)
10055 - RTE in JAVA
Hi.. I had posted in Java forum. But no reply
So i'm posting here...
I solved this problem using C++ (which is my usual language).
I am a newbie in Java...
I wanted to use Java in UVa. So i chose a easy problem(10055) to start with.
But...
RUNTIME ERROR is the only verdict i'm getting
Is my method of taking input wrong?
If so, what is the correct way??
Here is the code: ( Works fine in my computer )
![:-?](./images/smilies/icon_confused.gif)
So i'm posting here...
I solved this problem using C++ (which is my usual language).
I am a newbie in Java...
I wanted to use Java in UVa. So i chose a easy problem(10055) to start with.
But...
![:o](./images/smilies/icon_eek.gif)
RUNTIME ERROR is the only verdict i'm getting
![:oops:](./images/smilies/icon_redface.gif)
Is my method of taking input wrong?
If so, what is the correct way??
Here is the code: ( Works fine in my computer )
Code: Select all
Code deleted after AC... Thanks to mf...
Last edited by zyxw on Sun Jul 06, 2008 7:44 pm, edited 1 time in total.
I am not totally useless, because I can still be used as a bad example ![:P](./images/smilies/icon_razz.gif)
![:P](./images/smilies/icon_razz.gif)
Re: 10055 - Hashmat the Brave Warrior
Java's int can hold values in range 2^31 to 2^31-1.
Integer.parseInt(...) will throw an exception if its input lies outside this range, and for some cases in this problem it does. An uncaught exception is then reported to you as a runtime error.
Integer.parseInt(...) will throw an exception if its input lies outside this range, and for some cases in this problem it does. An uncaught exception is then reported to you as a runtime error.
Re: 10055 - Hashmat the Brave Warrior
Thanks mf for quick reply...
1) Should i use BigInteger?
2) I am getting RTE for another problem also (10519 - REALLY STRANGE).
I have posted here...
http://online-judge.uva.es/board/viewto ... =30#p95457
Since i'm getting RTE in both programs, i thought there might be some problem with taking input![:roll:](./images/smilies/icon_rolleyes.gif)
1) Should i use BigInteger?
2) I am getting RTE for another problem also (10519 - REALLY STRANGE).
I have posted here...
http://online-judge.uva.es/board/viewto ... =30#p95457
Since i'm getting RTE in both programs, i thought there might be some problem with taking input
![:roll:](./images/smilies/icon_rolleyes.gif)
I am not totally useless, because I can still be used as a bad example ![:P](./images/smilies/icon_razz.gif)
![:P](./images/smilies/icon_razz.gif)
Re: 10055 - Hashmat the Brave Warrior
You can use BigInteger if you like, but long type (which is a 64-bit integer) would be sufficient and more simple. But you should parse a string to long with Long.parseLong() method.
Perhaps, there are leading/trailing whitespace on some lines in the input. Try to use java.util.Scanner to parse input, it can take care of these whitespace.
I don't know what's wrong there.2) I am getting RTE for another problem also (10519 - REALLY STRANGE).
I have posted here...
viewtopic.php?f=25&t=12321&st=0&sk=t&sd=a&start=30#p95457
Perhaps, there are leading/trailing whitespace on some lines in the input. Try to use java.util.Scanner to parse input, it can take care of these whitespace.
Thanks a million MF...
Got AC after 10 RTEs
Thanks a million mf.
Initially when i had difficulty in reading input in Java, i followed your suggestion here...
http://online-judge.uva.es/board/viewto ... e02#p73516
Its nice to see the same person helping me now
P.S: Should i remove my code from this thread and from Java forum?
![:)](./images/smilies/icon_smile.gif)
Thanks a million mf.
Initially when i had difficulty in reading input in Java, i followed your suggestion here...
http://online-judge.uva.es/board/viewto ... e02#p73516
Its nice to see the same person helping me now
![:wink:](./images/smilies/icon_wink.gif)
Can you please show how to use it or can you give some links to read about them?Try to use java.util.Scanner to parse input, it can take care of these whitespace.
P.S: Should i remove my code from this thread and from Java forum?
I am not totally useless, because I can still be used as a bad example ![:P](./images/smilies/icon_razz.gif)
![:P](./images/smilies/icon_razz.gif)
Re: Thanks a million MF...
Here's a sample code which shows how to use Scanner:
As always, you can find all the documentation about Scanner in its javadocs:
http://java.sun.com/j2se/1.5.0/docs/api ... anner.html
Code: Select all
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new BufferedReader(
new InputStreamReader(System.in)));
while (in.hasNextBigInteger()) {
java.math.BigInteger n = in.nextBigInteger();
System.out.printf("%s^2 = %s\n", n, n.multiply(n)); // do something
}
}
}
http://java.sun.com/j2se/1.5.0/docs/api ... anner.html
Re: 10055 - RTE in JAVA (SOLVED)
I am not totally useless, because I can still be used as a bad example ![:P](./images/smilies/icon_razz.gif)
![:P](./images/smilies/icon_razz.gif)