Page 8 of 11
Re: 482 Permutation Arrays
Posted: Sun Nov 02, 2008 10:11 am
by andy0518
I think my array is big enough, but it is still Run Time Error.
Can anyone help me?
Thank you
Code: Select all
#include<iostream>
#include<algorithm>
#define MAX 600000
using namespace std;
int main()
{
int t,order[MAX];
char text[MAX];
char *token;
char item[MAX/2][100];
cin.getline(text,MAX);
t = atoi(text);
while(t--)
{
cin.getline(text,MAX);
cin.getline(text,MAX);
token = strtok(text," ");
for(int i=0; token != NULL; i++)
{
order[i] = atoi(token);
token = strtok(NULL," ");
}
cin.getline(text,MAX);
token = strtok(text," ");
int i;
for(i=0; token != NULL; i++)
{
strcpy(item[order[i]-1], token);
token = strtok(NULL," ");
}
for(int j=0; j<i; j++)
printf("%s\n",item[j]);
if(t != 0)
printf("\n");
}
return 0;
}
Re: 482 Permutation Arrays
Posted: Tue Nov 25, 2008 10:28 pm
by tanvir_cse
hi, u cant declare an array of size 600,000. array size can be 90000, or some greater than this. I got RTE just for declaring #define SIZE 100000

Re: 482 What A Trick
Posted: Wed Nov 26, 2008 12:12 am
by tanvir_cse
My Algo...
1.Take test case
2.declare an int array[80000]. Then take input like this

for first line i,e 3 1 2 )
ch='*'; i=0;
while(ch!='\n')
{
scanf("%d",&array[i++]);
scanf("%c",&ch);
}
3.then take second line of input using 2D array of characters by str[8000][80];
4. Do other process as u need for ur problem.
5. When u r submitting the code just make : 1.int array[100000] and str[20000][50]
Dont try to Run ur code after making change.It will not run for VC++ users
Thats the trick i used to get AC.
Re: 482 Permutation Arrays
Posted: Sun Feb 08, 2009 5:38 pm
by qwerty
Here is my code.i am getting RTE.I have decreased the array size several times.Please help me
Re: 482 Permutation Arrays
Posted: Sat Feb 14, 2009 6:51 am
by Obaida
I changed my code again and again but again and again wA!!!! someone plz help me.... At least prove me wrong..
I am getting mad....
Re: 482 Permutation Arrays
Posted: Sat Mar 14, 2009 6:50 am
by Obaida
Some one please give me test case.

Re: 482 Permutation Arrays
Posted: Sat Mar 14, 2009 10:26 am
by Moshiur Rahman
I think you have to change your method of "input taking" for second input line.
you can use the value of
i to take the second line. Note that, you will be given exactly
i floating point numbers.
So, you don't need to worry about the white spaces. You get the value of
i from the while loop that takes the first input line.
Just replace the for() loop with this one:
Code: Select all
for(k = 0; k < i; ++k)
{
scanf("%s",st[num[k]-1]);
}
So, you can get rid of the len[] array too.
Re: 482 Permutation Arrays
Posted: Sat Mar 14, 2009 11:00 am
by Obaida
Thanks for giving me a good lesson.
Thank you very much.

482 Permutation Arrays (HELP!!!!!!!!!!!!!!!!!)
Posted: Thu Jun 25, 2009 6:30 pm
by toru
HI, hope every1 is good here, but i m really sick of this problem, i don't know why i m repeatedly getting CE for this one, the judge says:...........
"
code.o: In function `main':
code.cpp:(.text+0xab): warning: the `gets' function is dangerous and should not be used.
code.o: In function `__static_initialization_and_destruction_0(int, int)':
code.cpp:(.text+0x19): relocation truncated to fit: R_X86_64_32 against `.bss'
code.o: In function `__tcf_0':
code.cpp:(.text+0x51): relocation truncated to fit: R_X86_64_32 against `.bss'
collect2: ld returned 1 exit status
"
i completely don't understand, plzzz anyone help me to get rid of it......................
THANKZ IN ADVANCE
TORU.
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
#define MAX 100000
struct List
{
char fir[50000];
char sec[50000];
}list[MAX];
int sort_function( const void *a, const void *b)
{
char *s, *t;
s = ((struct List*)a)->fir;
t = ((struct List*)b)->fir;
return strcmp(s,t);
}
int main()
{
char buf[MAX], *ch;
long kase, N, i;
cin>>kase;
while(kase--)
{
printf("\n");
N=0;
gets(buf);
ch=strtok(buf, " ");
while(ch)
{
strcpy(list[N].fir, ch);
N++;
ch=strtok(NULL, " ");
}
N=0;
gets(buf);
ch=strtok(buf, " ");
while(ch)
{
strcpy(list[N].sec, ch);
N++;
ch=strtok(NULL, " ");
}
qsort( (void *)list, N, sizeof(list[0]), sort_function);
for(i=0; i<N; i++)
cout<<list[i].sec<<endl;
if(kase != 0)
printf("\n");
}
return 0;
}
Re: 482 Permutation Arrays
Posted: Fri Jun 26, 2009 6:40 am
by mf
Your program allocates too much memory, almost 9Gb.
And gcc limits statically-allocated memory to only about 2-4Gb even in 64-bit mode. (And in 32-bit mode which judge uses, it should be even a lot less)
Re: 482 Permutation Arrays
Posted: Fri Jun 26, 2009 7:06 pm
by toru
ok mf,
almost 9Gb.
oh my god, dats too much, i better shorten up my array and then try, thankz..
toru.
Re: 482 Permutation Arrays
Posted: Tue Jul 21, 2009 8:13 pm
by toru
Re: 482 Permutation Arrays
Posted: Sat Oct 09, 2010 12:49 am
by ngockhanhdao
Can anybody help me explain why run-time error ? I tested the inputs and outputs and they're all correct.
Code: Select all
#include <iostream>
using namespace std;
int main()
{
int listIndex[10]; int length = 0;
char listFloat[10][10];
char listPermuted[10][10] = {NULL};
int n;
cin >> n; // get #of inputs
cin.ignore(256, '\n');
cout << endl;
for (int z = 0; z < n; z++)
{
// get the list of indexes
do
{
cin >> listIndex[length];
length++;
}while (cin.get() != '\n');
// get the list of float numbers
int i = 0;
while (i < length)
{
cin >> listFloat[i];
i++;
}
// now permuted array
int j;
for (i = 0; i < length; i++)
{
j = listIndex[i] - 1;
strcpy(listPermuted[j], listFloat[i]);
}
for (i = 0; i < length; i++)
{
cout << listPermuted[i] << endl;
}
length = 0;
cout << endl;
}
cout << endl;
system("pause");
return 0;
}
Re: 482 Permutation Arrays
Posted: Sat Nov 13, 2010 9:00 am
by bachachele
do not print a new line after the last output...,gave me a lot of pain

before getting AC.....
Re: 482 Permutation Arrays
Posted: Sun Dec 12, 2010 8:10 pm
by nhrahi
Can anybody please please help me with my code?i am getting wrong answer again and again but i cant find it.Just at least give me a hint about what is wrong here.thank you in advacne.