Page 11 of 16
Posted: Wed Jul 25, 2007 7:17 pm
by Sayeef
I get PE for this problem Please help:
Code: Select all
#include<stdio.h>
struct asci{
int val,pos;
};
void main()
{
asci a[256],temp;
int i=0,j=0;
char line[1000];
while(gets(line))
{
for(i=31;i<='z';i++)
{
a[i].pos=i;
a[i].val=0;
}
for(i=0;line[i];i++)
if(line[i]>31&&line[i]<='z')
a[line[i]].val+=1;
for(i=31;i<='z';i++)
for(j=i+1;j<='z';j++)
{
if(a[i].val>a[j].val)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
else if(a[i].val==a[j].val)
{
if(a[i].pos<a[j].pos)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=31;i<='z';i++)
{
if(a[i].val)
printf("%d %d\n",a[i].pos,a[i].val);
}
printf("\n");
}
}
WHy 10062 WA
Posted: Thu Jul 26, 2007 8:16 pm
by bishop
i checked all the input output
my output is same
but it gives WA
what should i do
Code: Select all
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
int main()
{
char str[3000],temp,ch[3000];
int i,j,l,num[3000],m,t,k,count,c,a;
queue<char> Q;
while(scanf("%s",str)!=EOF)
{
l=strlen(str);
sort(str,str+l);
for(i=0; i<l; i++)
Q.push(str[i]);
m=0;
num[m]=1;ch[m]=Q.front();
Q.pop();
while(!Q.empty())
{
if(Q.front()==ch[m])
{
Q.pop(); num[m]++;
}
else if(Q.front()!=ch[m])
{
m++;
ch[m]=Q.front(); num[m]=1;
Q.pop();
}
}
for(i=0; i<=m-1; i++)
{
for(j=0; j<=m-1-i; j++)
{
if(num[j]>num[j+1])
{
t=num[j];
num[j]=num[j+1];
num[j+1]=t;
temp=ch[j];
ch[j]=ch[j+1];
ch[j+1]=temp;
}
else if(num[j]==num[j+1])
{
if(ch[j]<ch[j+1])
{
temp=ch[j];
ch[j]=ch[j+1];
ch[j+1]=temp;
t=num[j];
num[j]=num[j+1];
num[j+1]=t;
}
}
}
}
for(i=0; i<=m; i++)
{c=ch[i]; cout <<c<<" "<< num[i]<<endl;}
cout <<endl;
}
return 0;
}
check
Posted: Sat Aug 04, 2007 9:01 pm
by bishop
any one can check this code
all the input output is right
for my code
but why WA
Re: check
Posted: Sun Aug 05, 2007 5:34 pm
by emotional blind
bishop wrote:any one can check this code
all the input output is right
for my code
but why WA
Strange !! I couldn't find any error!!!
just presentation was wrong..
In this situation normally i use very old and effective technique..
"Recode"
can you try? or you may wait for some expert help

Still PE please help..........
Posted: Wed Sep 05, 2007 7:41 am
by Sayeef
Code: Select all
#include<stdio.h>
struct asci{
int val,pos;
};
void main()
{
//freopen("h:\\out2.txt","w",stdout);
asci a[256],temp;
int i=0,j=0,flag=0;
char line[1000];
while(gets(line))
{
if(flag)
printf("\n");
else
flag=1;
for(i=31;i<='z';i++)
{
a[i].pos=i;
a[i].val=0;
}
for(i=0;line[i];i++)
if(line[i]>31&&line[i]<='z')
a[line[i]].val+=1;
for(i=31;i<='z';i++)
for(j=i+1;j<='z';j++)
{
if(a[i].val>a[j].val)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
else if(a[i].val==a[j].val)
{
if(a[i].pos<a[j].pos)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=31;i<='z';i++)
{
if(a[i].val)
printf("%d %d\n",a[i].pos,a[i].val);
}
}
//fclose(stdout);
}
[/b]
Posted: Wed Sep 05, 2007 8:10 am
by Bappi_cuet
The size of line must be 1001.
If you get Ac please remove your code.
10062 WA plz help me
Posted: Sun Oct 28, 2007 1:37 pm
by alamgir kabir
Thank u shapnil;
I have got acc.
Posted: Sun Oct 28, 2007 5:23 pm
by sapnil
To alamgir
-> Your code given output for '\n'
Hope it helps.
** plz remove your code after acc.
Thanks
Keep posting
Sapnil
Posted: Thu Nov 15, 2007 11:00 am
by jtrmn
i have a problem of 10062
it sill wa
I don't know why.
please help me
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
char s[1001];
int counter[128];
void count();
int main()
{int c,j;
while(fgets(s,1001,stdin))
{s[strlen(s) - 1 ] = '\0';
for(c=0;c<128;c++)
counter[c]=0;
count();
for(j=1;j<1001;j++)
for(c=127;c>=32;c--)
if(counter[c]==j)
printf("%d %d\n",c,counter[c]);
printf("\n");
}
return 0;
}
void count()
{int i,c;
for(c=0;s[c]!='\0';c++)
for(i=32;i<128;i++)
if(s[c]==i)
counter[i]++;
return;
}
Posted: Mon Nov 19, 2007 4:38 am
by laicc86
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
char ch[1001];
int i,asc,temp,temp2,ch_temp,ch_temp2,ch_num;
while (gets(ch))
{
int l[1001]={0},k[1001]={0},q=0,w=0,e;
ch_num=strlen(ch);
for (i=0;i<ch_num;i++)
{
asc=ch[i];
l[asc]++;
}
for (i=32,e=0;i<128;i++)
{
if (l[i]!=NULL)
{
ch[e]=i;
k[e]=l[i];
e++;
}
}
//sorting part according the frequencies
for (i=0,temp=k[0],ch_temp=ch[0];i<e;i++)
{
if (temp>k[i])
{
temp2=temp;
temp=k[i];
k[i]=temp2;
k[w]=temp;
ch_temp2=ch_temp;
ch_temp=ch[i];
ch[i]=ch_temp2;
ch[w]=ch_temp;
}
if (q==e-1)
{
w++;
q=w-1;
temp=k[w];
ch_temp=ch[w];
i=w-1;
}
q++;
}
//sorting part acording the ASCII, if the frequency is same
for (i=0;i<e;i++)
{
if (k[i]==k[i+1])
{
if (ch[i]<ch[i+1])
{
ch_temp=ch[i];
ch_temp2=ch[i+1];
ch[i]=ch_temp2;
ch[i+1]=ch_temp;
i=-1;
}
}
}
//print part
for (i=0;i<e;i++)
{
printf("%d %d\n",ch[i],k[i]);
}
printf ("\n");
}
}
i know it's abit messy
i get WA with this code...i had try many kinds of input and didn't find any error....
can anyone help me?
Re: 10062 - Tell me the frequencies WA?
Posted: Sun May 04, 2008 12:36 pm
by Obaida
Some one please tell me where is my problem... I followed what they said..
Re:
Posted: Wed May 07, 2008 5:28 am
by amr saqr
jtrmn wrote:i have a problem of 10062
it sill wa
I don't know why.
please help me
Hi jtrmn,
the problem description says "A blank line should separate each set of output.", that means that you should print blank line between cases' outputs,
and your program print blank line after each one,
hope i helped u.
Re:
Posted: Wed May 07, 2008 5:31 am
by amr saqr
laicc86 wrote:
i know it's abit messy
i get WA with this code...i had try many kinds of input and didn't find any error....
can anyone help me?
Same Mistake that jtrmn did
read my previous reply

Re: 10062 - Tell me the frequencies WA?
Posted: Wed May 07, 2008 5:39 am
by amr saqr
Obaida wrote:Some one please tell me where is my problem... I followed what they said..
Yes Obaida, you followed what they said

,
but u did a simple mistake,
read the input from a file, just put one test case in this file, say it will be AAABBC,
and display the output on the console,
run the program, and you will find that your program displays 2 outputs as if there were 2 input test cases in your file,
hope i helped u

Re: 10062 - Tell Me the Frequencies!
Posted: Thu May 08, 2008 9:39 am
by Obaida