482 - Permutation Arrays
Moderator: Board moderators
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
482 Run Time Error (?)
Why runtime error......
#include <stdio.h>
char y[1000][1000],z;
int main()
{
int x[1000],b,c,d,e,f;
scanf("%d",&b);
for(c=0;c<b;c++)
{
e=1;
while(scanf("%d%c",&x[e],&z)==2)
{
if(z=='\n')
{
break;
}
e++;
}
for(d=1;d<=e;d++)
{
f=x[d];
scanf("%s",y[f]);
}
for(d=1;d<=e;d++)
{
printf("%s\n",y[d]);
}
if(c!=b-1)
{
printf("\n");
}
}
return 0;
}
#include <stdio.h>
char y[1000][1000],z;
int main()
{
int x[1000],b,c,d,e,f;
scanf("%d",&b);
for(c=0;c<b;c++)
{
e=1;
while(scanf("%d%c",&x[e],&z)==2)
{
if(z=='\n')
{
break;
}
e++;
}
for(d=1;d<=e;d++)
{
f=x[d];
scanf("%s",y[f]);
}
for(d=1;d<=e;d++)
{
printf("%s\n",y[d]);
}
if(c!=b-1)
{
printf("\n");
}
}
return 0;
}
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
Anyone help me please... I also get Runtime Error without knowing where my mistake is... I've changed the array size into 100000 but still getting Runtime Error... here's my code:
Please help me... 
Code: Select all
AC already

Last edited by Roby on Thu Apr 20, 2006 9:54 am, edited 1 time in total.
This part of your code:
What if num += dataIndex - 48 >= 10? You never handle the carry.
Code: Select all
// get the number
while ( dataIndex[i] != ' ' && dataIndex[i] != '\n' &&
dataIndex[i] != '\0' )
{
num *= 10;
num += dataIndex[i] - 48;
i++;
}
I don't know - I used Java's StringTokenizer which, by default, considers all white spaces - try checking for tabs, carriage returns, that sort of thing.
I assumed lines to be at most 50000 characters long. I didn't do anything special, just read it and sorted (which was weird, usually I have problems with I/O with Java).
Maybe it's gets(), sometimes it behaves in misterious ways?
Darko
I assumed lines to be at most 50000 characters long. I didn't do anything special, just read it and sorted (which was weird, usually I have problems with I/O with Java).
Maybe it's gets(), sometimes it behaves in misterious ways?
Darko
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
I've changed the code like you said above, and there were no difference... My first approach just changed the SIZE value become 512 and I got RE and the other approach I changed the SIZE value and changed the scanf and I got WA...
OMG, how I should change my code... it seems perfect in my computer but why judge always gave me WA or RE...
OMG, how I should change my code... it seems perfect in my computer but why judge always gave me WA or RE...

I really didn't want to have to post AC code here, appearently you're too frustrated to think...
The code is really base on yours...When I said use strtok, I implicity says that SIZE = 100 is not enough..
The code is really base on yours...When I said use strtok, I implicity says that SIZE = 100 is not enough..
Code: Select all
Cut after he got it
Last edited by yiuyuho on Thu Apr 20, 2006 5:50 am, edited 1 time in total.
mamun wrote:for ( i = 0, j = 0; dataIndex != '\n' && dataIndex != '\0'; i++ )
You are incrementing i in the loop block. So don't do it here.
I don't think that's an issue, because the pre-condition for i to enter the outer-loop is that i is pointing at a non space character (if not the while will make it so), the post-condition for leaving the inner loop is that i is pointing at a space, so the i++ will get rig of the space.
By the way, I'll take off the above code in 2 days.
yiuyuho wrote:mamun wrote:for ( i = 0, j = 0; dataIndex != '\n' && dataIndex != '\0'; i++ )
You are incrementing i in the loop block. So don't do it here.
I don't think that's an issue, ...
But well, it is. Test the code with input like
Code: Select all
2
3 1 2
32.0 54.7 -2
3 1 2
32.0 54.7 -2