Kamanashish wrote:Hi, i am getting RTE(SIGSEGV), please help.
[cpp]
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void main ()
{
int i,j,n,last[1000],max;
char *a;
while(gets(a))
[/cpp]
char *a allocates space for an uninitialized pointer, so you are reading your input into random mem -> segmentation fault.
You can use malloc to dinamically allocate sufficient storage for the input data or declare an array big enough.
It's not the trap u r thinking. my code doesn't print any thing incase of a blank line. there is no blank line in the input file. If there were blank line in the judges input file then u might got WA
int main()
{
int i,j,x,k; /*counters*/
char c[10000]; /*Characters for every line*/
char temp[10000];
int rep[10000];
int index,min;
while(1)
{
i=index=0;
while(c[i-1]!='\n')
{ /*Read until NewLine*/
scanf("%c",&c);
if (c=='\n' && i==0)
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0\n");
else if (c!=' ')
i++;
}
i--;
for (j=0;j<i;j++)
for (x=j+1;x<=i;x++) /*Compare since first letter*/
if (c[j]==c[x])
rep[j]++; /*If they are equals rep[number of letter]++*/
temp[0]=c[0];
for (x=1;x<i;x++)
{
if (rep[x]>rep[0])
{
temp[index]=c[x];
rep[0]=rep[x];
rep[x]=0;
}
}
for (x=1;x<i;x++)
if (rep[x]==rep[0])
{
index++;
temp[index]=c[x];
}
for (k=0;k<index;k++)
{
min=k;
for (j=k+1;j<=index;j++) /*Selection Sort*/
if (temp[j]<temp[min])
swap(&temp[j],&temp[min]);
}
for (k=0;k<=index;k++)
printf("%c",temp[k]);
printf(" %d\n",rep[0]+1);
for (j=0;j<=i;j++) /*Put all 0's in the array*/
rep[j]=0;
}
return 0;
}[/c]
int main()
{
int i,j,x,k; /*counters*/
char c[10000]; /*Characters for every line*/
char temp[10000];
int rep[10000];
int index,min;
while(1)
{
i=index=0;
while(c[i-1]!='\n')
{ /*Read until NewLine*/
scanf("%c",&c);
if (c==EOF) /*I ADD THIS PART IN THE CODE*/
return 0;
else if (c=='\n' && i==0)
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0\n");
else if (c!=' ')
i++;
}
i--;
for (j=0;j<i;j++)
for (x=j+1;x<=i;x++) /*Compare since first letter*/
if (c[j]==c[x])
rep[j]++; /*If they are equals rep[number of letter]++*/
temp[0]=c[0];
for (x=1;x<i;x++)
{
if (rep[x]>rep[0])
{
temp[index]=c[x];
rep[0]=rep[x];
rep[x]=0;
}
}
for (x=1;x<i;x++)
if (rep[x]==rep[0])
{
index++;
temp[index]=c[x];
}
for (k=0;k<index;k++)
{
min=k;
for (j=k+1;j<=index;j++) /*Selection Sort*/
if (temp[j]<temp[min])
swap(&temp[j],&temp[min]);
}
for (k=0;k<=index;k++)
printf("%c",temp[k]);
printf(" %d\n",rep[0]+1);
for (j=0;j<=i;j++) /*Put all 0's in the array*/
rep[j]=0;
}
return 0;
} [/c]
And I still got TLE.
Could it be another reason???
thanks a lot!!
bye
Same reason. Your not reading input correctly. scanf returns EOF "if an input failure occurs before any conversion such as an end-of-file occurs" (man scanf)
I'm getting WA all the time... and I can't understand why. There must be a tricky input...
I've 2 questions:
1. Does the last line of input finish with '\n' or just with feof ???
2. What we are suposed to do if there is a blank line or a line with no valid characters ?? do we have to print "ABC...XYZabc....xyz 0" in both cases??