11115 - Uncle Jack
Moderator: Board moderators
Re: 11115 - Uncle Jack
Hello,
I'm a Java newbie. Can somebody tell my why does this code generate a Runtime Error? Thanks in advance.
Thanks a lot for the help.
I'm a Java newbie. Can somebody tell my why does this code generate a Runtime Error? Thanks in advance.
Code: Select all
import java.io.*;
import java.util.*;
import java.math.*;
class UncleJack
{
static BufferedReader stdin;
static PrintWriter stdout;
public static void main(String[] ss) throws Exception
{
Reader rdr = new InputStreamReader(System.in);
stdin = new BufferedReader(rdr);
Writer wtr = new OutputStreamWriter(System.out);
wtr = new BufferedWriter(wtr);
stdout = new PrintWriter(wtr);
(new UncleJack()).run();
stdout.close();
}
void run() throws Exception
{
StringTokenizer t = new java.util.StringTokenizer(stdin.readLine());
int n = Integer.parseInt(t.nextToken());
int d = Integer.parseInt(t.nextToken());
while (n + d != 0){
BigInteger b = new BigInteger(String.valueOf(n));
b = b.pow(d);
stdout.println(b.toString());
t = new java.util.StringTokenizer(stdin.readLine());
n = Integer.parseInt(t.nextToken());
d = Integer.parseInt(t.nextToken());
}
}
}
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.
Are you dreaming right now?
http://www.dreamviews.com
Are you dreaming right now?
http://www.dreamviews.com
11115 - Uncle Jack - RE
Code: Select all
Removed after ACed!!!!
Last edited by aeiou on Wed Jun 04, 2008 5:06 am, edited 1 time in total.
Re: 11115 - Uncle Jack
I think the problem is the Big Integer class. The code I posted just before your post also gets a Runtime Error. I changed it to not use BigInteger and got Wrong Answer instead.
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.
Are you dreaming right now?
http://www.dreamviews.com
Are you dreaming right now?
http://www.dreamviews.com
Re: 11115 - Uncle Jack
To andmej ,
I think the problem is not with with BigInt usage ...
May be I can send my code to u as a PM !!!
I think the problem is not with with BigInt usage ...
May be I can send my code to u as a PM !!!
Re: 11115 - Uncle Jack
all the test cases:
1 0
1 1 ...
1 25
2 0 ...
2 25
...
10 0 ...
10 25
my outputs are the same as what UVA TOOLKIT does, but still WA...
why?
thx!
1 0
1 1 ...
1 25
2 0 ...
2 25
...
10 0 ...
10 25
my outputs are the same as what UVA TOOLKIT does, but still WA...
why?
thx!
Re: 11115 - Uncle Jack
getting TLE...please help..
here is the code..
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
using namespace std;
typedef int BigN[1000];
BigN a;
BigN result;
void print(BigN num)
{
for(int i = num[0]; i > 0; --i)
cout << num;
cout << endl;
}
int to_int(string &str)
{
int len = str.size();
int dec = 0;
for(int i=0; i < len; ++i)
{
dec = (dec * 10) + (str - '0');
}
return dec;
}
void solve( string &nep, string &cds)
{
int nepw = to_int(nep);
int count = to_int(cds);
int len = nep.size();
a[0] = len;
for(int i = 1; i <= len; ++i)
a = nep[len-i] - '0';
while(--count)
{
int len = a[0];
a[0] = 0;
int c = 0;
for(int i=1; i <= len || c; ++i)
{
int newdig = (a * nepw) + c;
if( newdig > 9)
{
a = newdig % 10;
c = newdig / 10;
}
else
{
a = newdig;
c = 0;
}
++a[0];
}
}
print(a);
}
int main()
{
string nep, cds;
while( cin >> nep >> cds )
{
if(nep[0] == '0' && cds[0] == '0')
break;
solve(nep, cds);
memset(&a, 0, sizeof(a));
nep.clear();
cds.clear();
}
return 0;
}
here is the code..
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
using namespace std;
typedef int BigN[1000];
BigN a;
BigN result;
void print(BigN num)
{
for(int i = num[0]; i > 0; --i)
cout << num;
cout << endl;
}
int to_int(string &str)
{
int len = str.size();
int dec = 0;
for(int i=0; i < len; ++i)
{
dec = (dec * 10) + (str - '0');
}
return dec;
}
void solve( string &nep, string &cds)
{
int nepw = to_int(nep);
int count = to_int(cds);
int len = nep.size();
a[0] = len;
for(int i = 1; i <= len; ++i)
a = nep[len-i] - '0';
while(--count)
{
int len = a[0];
a[0] = 0;
int c = 0;
for(int i=1; i <= len || c; ++i)
{
int newdig = (a * nepw) + c;
if( newdig > 9)
{
a = newdig % 10;
c = newdig / 10;
}
else
{
a = newdig;
c = 0;
}
++a[0];
}
}
print(a);
}
int main()
{
string nep, cds;
while( cin >> nep >> cds )
{
if(nep[0] == '0' && cds[0] == '0')
break;
solve(nep, cds);
memset(&a, 0, sizeof(a));
nep.clear();
cds.clear();
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11115 - Uncle Jack
input:Output should be 1 in less than 3 seconds.
Code: Select all
1 0
0 0
Check input and AC output for thousands of problems on uDebug!
Re: 11115 - Uncle Jack
hi, output is 1, i have tested with my program, but still getting WA, if WA gets corrected, then I will look into TLE if any.
any suggestion.
any suggestion.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11115 - Uncle Jack
https://ideone.com/qMfWfC
The code you posted times out.
The code you posted times out.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11115 - Uncle Jack
The answer is N.pow(D), use bigint.
Check input and AC output for thousands of problems on uDebug!