## 10062 - Tell me the frequencies!

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Sayeef
New poster
Posts: 12
Joined: Sun Jun 18, 2006 3:06 am
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");
}

}

``````

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

### WHy 10062 WA

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;
}

``````

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

### check

any one can check this code
all the input output is right
for my code
but why WA

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

### Re: check

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

Sayeef
New poster
Posts: 12
Joined: Sun Jun 18, 2006 3:06 am

### Still PE please help..........

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]

Bappi_cuet
New poster
Posts: 14
Joined: Wed Jul 11, 2007 4:26 pm
Location: CSE, CUET. Chittagong, Bangladesh.
Contact:
The size of line must be 1001.
If you get Ac please remove your code.
---------------------------------------------
IT'S TIME TO GO AHEAD !!!!
---------------------------------------------

alamgir kabir
New poster
Posts: 37
Joined: Wed Oct 03, 2007 10:42 am

### 10062 WA plz help me

Thank u shapnil;
I have got acc.

Code: Select all

``````
//code removed

``````
Last edited by alamgir kabir on Mon Oct 29, 2007 1:47 pm, edited 1 time in total.

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:
To alamgir

-> Your code given output for '\n'

Hope it helps.

** plz remove your code after acc.

Thanks
Keep posting
Sapnil
"Dream Is The Key To Success"

@@@ Jony @@@

jtrmn
New poster
Posts: 1
Joined: Wed Nov 14, 2007 6:49 pm
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;
}

``````

laicc86
New poster
Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm

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?

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

### Re: 10062 - Tell me the frequencies WA?

Some one please tell me where is my problem... I followed what they said..

Code: Select all

``DELETED``
Last edited by Obaida on Tue Aug 05, 2008 7:04 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.

amr saqr
New poster
Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

### Re:

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.
C++ Is The Best.

amr saqr
New poster
Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

### Re:

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
C++ Is The Best.

amr saqr
New poster
Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

### Re: 10062 - Tell me the frequencies WA?

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
C++ Is The Best.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

### Re: 10062 - Tell Me the Frequencies!

Code: Select all

``Thanks I get Accepted.``
try_try_try_try_&&&_try@try.com
This may be the address of success.