Page 7 of 12

Posted: Sat Mar 10, 2007 12:10 pm
by shamim
There is a lot of data in the input file.
So you could speed up the input/output process.
Usually, people use fread and fwrite to speed up I/O.

10055

Posted: Tue Mar 13, 2007 11:05 pm
by mnthk
hey!
*use simply double data type
* subtract the low value from the high value always.
Then u get AC
bye

10055 Hashmat the brave warrior ( How it could be wrong !! )

Posted: Sun Mar 02, 2008 6:15 pm
by Zikas
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

Posted: Mon Mar 03, 2008 3:53 pm
by CSEDU_1323
vice versa x<y or x>y is possible
so D result = greater num - smaller num
&& use long long

Posted: Sun Mar 09, 2008 7:59 pm
by scott1991
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;
}

Posted: Sun Mar 09, 2008 8:58 pm
by emotional blind
scott1991 wrote:WHAT AM I DOING WRONG?????
input can be as large as 2^32, but unsigned integer can hold 2^32-1 at maximum.

Re: 10055 - Hashmat the Brave Warrior

Posted: Wed Jul 02, 2008 5:02 am
by lnr
starrynight says
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! :o

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;
}

It may help.

10055 - RTE in JAVA (SOLVED)

Posted: Thu Jul 03, 2008 9:39 am
by zyxw
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... :o
RUNTIME ERROR is the only verdict i'm getting :oops:

I don't think there is any error in algorithm :wink:
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...

10055 - RTE in JAVA

Posted: Sun Jul 06, 2008 2:29 pm
by zyxw
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... :o
RUNTIME ERROR is the only verdict i'm getting :oops:

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...

Re: 10055 - Hashmat the Brave Warrior

Posted: Sun Jul 06, 2008 4:45 pm
by mf
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.

Re: 10055 - Hashmat the Brave Warrior

Posted: Sun Jul 06, 2008 5:05 pm
by zyxw
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:

Re: 10055 - Hashmat the Brave Warrior

Posted: Sun Jul 06, 2008 6:06 pm
by mf
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.
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
I don't know what's wrong there.
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...

Posted: Sun Jul 06, 2008 6:53 pm
by zyxw
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 :wink:
Try to use java.util.Scanner to parse input, it can take care of these whitespace.
Can you please show how to use it or can you give some links to read about them?

P.S: Should i remove my code from this thread and from Java forum?

Re: Thanks a million MF...

Posted: Sun Jul 06, 2008 7:37 pm
by mf
Here's a sample code which shows how to use Scanner:

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
        }
    }
}
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

Re: 10055 - RTE in JAVA (SOLVED)

Posted: Sun Jul 06, 2008 7:48 pm
by zyxw
After following mf's suggestion, got AC :lol:
http://online-judge.uva.es/board/viewto ... 2e0#p95456