Page 2 of 7
Thank you
Posted: Wed Aug 13, 2003 11:32 am
by willy
Oh,

Calculation error

heehee thanks for pointing it out
499 What's the frequency Kenneth
Posted: Wed Dec 17, 2003 3:20 pm
by Kamanashish
Hi, i am getting RTE(SIGSEGV), please help.
[cpp]
CUT
[/cpp]
Re: 499 What's the frequency Kenneth
Posted: Wed Dec 17, 2003 5:06 pm
by CDiMa
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.
Ciao!!!
Claudio
Posted: Thu Dec 18, 2003 10:21 am
by sohel
Your code is perfectly alright apart from the correction suggested.
I have changed that part of your code and got it AC. Edit that part and Submit.
Posted: Tue Mar 16, 2004 11:25 am
by soyoja
In this problem, one of trap is input data is "Blank line".
When blank line received, your program must print
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
Plz check it

Posted: Tue Mar 16, 2004 11:26 am
by soyoja
In this problem, one of trap is input data is "Blank line".
When blank line received, your program must print
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
Plz check it

Posted: Tue Mar 16, 2004 8:12 pm
by prince56k
To soyoja,
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

Posted: Fri May 07, 2004 4:23 am
by GreenPenInc
499 is disgusting and abhorrent. It smacks of ignorance and should immediately be removed from the problem set.
Posted: Fri May 21, 2004 4:25 am
by midra
I got TLE in this problem...
is there any special Input/Output for this problem???
Here is my code:
[c]
#include <stdio.h>
char swap (char *a,char *b)
{
*a^=*b;
*b^=*a;
*a^=*b;
}
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]
Posted: Fri May 21, 2004 5:34 am
by UFP2161
You have a while(1) that never breaks.
Posted: Sat May 22, 2004 4:09 am
by midra
thanks... but
I have changed for this:
[c]
#include <stdio.h>
char swap (char *a,char *b)
{
*a^=*b;
*b^=*a;
*a^=*b;
}
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
Posted: Sat May 22, 2004 4:15 am
by UFP2161
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)
Posted: Sat May 22, 2004 10:07 pm
by midra
Thanks! I Finally Got AC!!!:D
good luck!
byee!
Posted: Tue Jun 22, 2004 4:13 pm
by [senu]
I got WA and I dont know why, Can You help me?
BTW I think ACM.UVA should delete/change problems like that. I hate easy problems with stupid inputs and outputs like 739.
[cpp]
#include <stdio.h>
#include <iostream>
#define MAX 256
#define f(x)for(int i=0; i<=x; i++)
#define f2(x,y)for(int i=x; i<=y; i++)
using namespace std;
int i,k,j,l,m,n,qq,a,b,c,maxc;
char s[MAX];
int t[255];
void rob(char *s)
{
f(254) t=0;
maxc=0;
int i=0,j,k,l;
while(s!='\0' && s!='\n')
{
t[int(s)]++;
if(t[int(s)]>maxc && int(s)!=32) maxc=t[int(s)];
/* previous version */
// if(t[int(s)]>maxc && ((int(s)>=65 && int(s)<=90) ||(int(s[i])>=97 && int(s[i])<=122))) maxc=t[int(s[i])];
i++;
}
f2(35,255) /* there were 2 fors (1st 65->90 & 2nd 97->122)*/
{
if (t[i]==maxc) cout << char(i);
}
cout << " " << maxc << endl;
}
int main()
{
while(cin)
{
cin.getline(s,MAX);
rob(s);
}
return 0;
}
[/cpp]
499 - WA
Posted: Sat Aug 14, 2004 12:33 am
by txandi

I hate problems like this one... too easy...
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??
Thanks a lot!