10062 - Tell me the frequencies!
Moderator: Board moderators
10062WA : why ???
This is my code ..... i dunno why wrong ans ..... what's wrong here ????
plz help me ....
#include<stdio.h>
#include<string.h>
char A[1010],B[1010],ch;
int intB[1010],intC[1010];
void main(void)
{
int c,i,j,k,len,f;
while(gets(A))
{
len=strlen(A);
strcpy(B,A);
k=0;c=0;f=1;ch=0;
for(i=0;i<1010;i++)intC=0;
for(i=0;i<1010;i++)intB=0;
for(i=0;i<len;i++)
{
if(f==1)
{
for(j=i;j<len;j++)
{
if(A==B[j])
{
intC[c]++;
ch=A;
B[j]=0;
f=0;
}
else
{
c++;i=j-1;
intB[k++]=ch;
f=1;
break;
}
/*if(f==0)
{
i=j-1;
f=0;
}
else f=0; */
}
}
}
intB[k++]=ch;
for(i=0;intC;i++)
{
for(j=i+1;intC[j];j++)
{
if(intC>intC[j] || (intC==intC[j] && intB<intB[j]))
{
intC^=intC[j]^=intC^=intC[j];
intB[i]^=intB[j]^=intB[i]^=intB[j];
}
}
}
for(i=0;intC[i];i++)printf("%d %d\n",intB[i],intC[i]);
printf("\n");
}
}
this is my code ..
plz help me ....

#include<stdio.h>
#include<string.h>
char A[1010],B[1010],ch;
int intB[1010],intC[1010];
void main(void)
{
int c,i,j,k,len,f;
while(gets(A))
{
len=strlen(A);
strcpy(B,A);
k=0;c=0;f=1;ch=0;
for(i=0;i<1010;i++)intC=0;
for(i=0;i<1010;i++)intB=0;
for(i=0;i<len;i++)
{
if(f==1)
{
for(j=i;j<len;j++)
{
if(A==B[j])
{
intC[c]++;
ch=A;
B[j]=0;
f=0;
}
else
{
c++;i=j-1;
intB[k++]=ch;
f=1;
break;
}
/*if(f==0)
{
i=j-1;
f=0;
}
else f=0; */
}
}
}
intB[k++]=ch;
for(i=0;intC;i++)
{
for(j=i+1;intC[j];j++)
{
if(intC>intC[j] || (intC==intC[j] && intB<intB[j]))
{
intC^=intC[j]^=intC^=intC[j];
intB[i]^=intB[j]^=intB[i]^=intB[j];
}
}
}
for(i=0;intC[i];i++)printf("%d %d\n",intB[i],intC[i]);
printf("\n");
}
}
this is my code ..
10062 - Tell me the frequencies
I know the code is badly written, but I cannot find the input set that cracked it. It gives WA. I tried a lot of weird input, but could not get unexpected results.
[cpp]#include <iostream.h>
#include <string.h>
void main() {
char temp[2000];
int freq[129];
int i;
bool firsttime = true;
cin.getline(temp, 2000);
while (1) {
if (!firsttime) cout << endl;
firsttime = false;
for (i = 0; i < 129; i++) freq = 0;
for (i = 0; temp; i++) {
freq[int(temp)]++;
}
int minfreq;
minfreq = 10000;
for (i = 0; i < 129; i++) if (freq < minfreq && freq != 0) minfreq = freq;
while (minfreq < 9999) {
for (i = 127; i >= 32; i--) {
if (freq == minfreq) {
cout << i << " " << freq << endl;
freq = 10000;
}
}
minfreq = 10000;
for (i = 0; i < 129; i++) if (freq < minfreq && freq[i] != 0) minfreq = freq[i];
}
cin.getline(temp, 2000);
char ch;
cin.get(ch);
if (!cin.eof()) cin.putback(ch); else break;
}
}[/cpp]
[cpp]#include <iostream.h>
#include <string.h>
void main() {
char temp[2000];
int freq[129];
int i;
bool firsttime = true;
cin.getline(temp, 2000);
while (1) {
if (!firsttime) cout << endl;
firsttime = false;
for (i = 0; i < 129; i++) freq = 0;
for (i = 0; temp; i++) {
freq[int(temp)]++;
}
int minfreq;
minfreq = 10000;
for (i = 0; i < 129; i++) if (freq < minfreq && freq != 0) minfreq = freq;
while (minfreq < 9999) {
for (i = 127; i >= 32; i--) {
if (freq == minfreq) {
cout << i << " " << freq << endl;
freq = 10000;
}
}
minfreq = 10000;
for (i = 0; i < 129; i++) if (freq < minfreq && freq[i] != 0) minfreq = freq[i];
}
cin.getline(temp, 2000);
char ch;
cin.get(ch);
if (!cin.eof()) cin.putback(ch); else break;
}
}[/cpp]
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
10062 - Tell me the frequencies WA?
[c]
#include<stdio.h>
#include<string.h>
int l,stat[200],m,i,j,n,num[1010],sum[1010],t;
char a[1050];
void main(){
while(gets(a)){
l=strlen(a);
for(i=0;i<l;i++) stat[a]++;
for(i=33,n=0;i<129;i++){
if(stat){
num[n]=i;
sum[n]=stat;
stat=0;
n++;
}
}
//Sorting part
for(i=0,m=n-1;i<m;i++){
t=i;
for(j=i+1;j<n;j++){
if(sum[j]<=sum[t]){
if(sum[j]==sum[t]){
if(num[t]<num[j]) t=j;
}
else t=j;
}
}
if(t!=i){
l=num[t];num[t]=num;num=l;
l=sum[t];sum[t]=sum;sum=l;
}
}
//Printing part
for(i=0;i<n;i++) printf("%i %i\n",num,sum);
printf("\n");
}
}
[/c]
Can anybody tell me where my mistake is?
Thanks in advance!
#include<stdio.h>
#include<string.h>
int l,stat[200],m,i,j,n,num[1010],sum[1010],t;
char a[1050];
void main(){
while(gets(a)){
l=strlen(a);
for(i=0;i<l;i++) stat[a]++;
for(i=33,n=0;i<129;i++){
if(stat){
num[n]=i;
sum[n]=stat;
stat=0;
n++;
}
}
//Sorting part
for(i=0,m=n-1;i<m;i++){
t=i;
for(j=i+1;j<n;j++){
if(sum[j]<=sum[t]){
if(sum[j]==sum[t]){
if(num[t]<num[j]) t=j;
}
else t=j;
}
}
if(t!=i){
l=num[t];num[t]=num;num=l;
l=sum[t];sum[t]=sum;sum=l;
}
}
//Printing part
for(i=0;i<n;i++) printf("%i %i\n",num,sum);
printf("\n");
}
}
[/c]
Can anybody tell me where my mistake is?
Thanks in advance!
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
consider the following part:
you've made increment for variable stat, but you didnt initialize the variable first. try to initialize first.
titid gede
Code: Select all
for(i=0;i<l;i++) stat[a[i]]++;
titid gede
Kalo mau kaya, buat apa sekolah?
The problem statement says:
This means that the character having ASCII value of 128 can also be part of the input file. Your program is unable to handle it.The given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with ‘\n’ and ‘\r’ but always keep those out of consideration.
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
For titid_gede, I've tried to intialize :
[c]
for(i=0;i<200;i++) stat=0;
[/c]
I put that line between void main(){ and while(gets(a)){ but still WA.
And for shamim, I dunno the maximum ASCII value (255 or 256), so just in case, in the program I use:
[c]
for(i=33,n=0;i<129;i++)
[/c]
So the value of i can reach 128.
Still WA, though. Help plz.
Thanks
[c]
for(i=0;i<200;i++) stat=0;
[/c]
I put that line between void main(){ and while(gets(a)){ but still WA.
And for shamim, I dunno the maximum ASCII value (255 or 256), so just in case, in the program I use:
[c]
for(i=33,n=0;i<129;i++)
[/c]
So the value of i can reach 128.
Still WA, though. Help plz.
Thanks
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia
Apparently, the ASCII value range is from 0 - 255 like titid_gede said. This would mean the first 32 ASCII would be from 0-31 and the last 128 ASCII would be 128-255.
In that case I just change the line
[c]
for(i=33,n=0;i<128;i++)
[/c]
with
[c]
for(i=32,n=0;i<128;i++)
[/c]
And now Got it ACC, but with PE. Oh well, that's better than WA anyway.
Thanks for the help guys !!

In that case I just change the line
[c]
for(i=33,n=0;i<128;i++)
[/c]
with
[c]
for(i=32,n=0;i<128;i++)
[/c]
And now Got it ACC, but with PE. Oh well, that's better than WA anyway.
Thanks for the help guys !!


10062
I don't understand, why I got the 10008 AC
but the similar 10062 WA.
Please help or give the test case.
Thanks in advance.
[cpp]#include <iostream>
using namespace std;
int const Max=1000;
void Output(int T[],int cnt,int position)
{
int i;
for(i=position;i>=0;i--)
if(T==cnt) cout<<i<<' '<<T<<endl;
}
void main()
{
char S[Max]={NULL};
while(cin.getline(S,Max))
{
int T[128]={0}; // to store the number of freqency
int length=cin.gcount()-1;
int i=0;
while(S)
{
T[int(S)]++;
i++;
}
int cnt=Max,position;
for(i=127;i>=0;i--)
if(T&&T<cnt)
{
cnt=T; // find the smallest one in the alphabet & position
position=i;
}
while(cnt<=1000)
{
Output(T,cnt,position);
position=127;
cnt++;
}
cout<<endl;
}
}[/cpp]
but the similar 10062 WA.
Please help or give the test case.
Thanks in advance.
[cpp]#include <iostream>
using namespace std;
int const Max=1000;
void Output(int T[],int cnt,int position)
{
int i;
for(i=position;i>=0;i--)
if(T==cnt) cout<<i<<' '<<T<<endl;
}
void main()
{
char S[Max]={NULL};
while(cin.getline(S,Max))
{
int T[128]={0}; // to store the number of freqency
int length=cin.gcount()-1;
int i=0;
while(S)
{
T[int(S)]++;
i++;
}
int cnt=Max,position;
for(i=127;i>=0;i--)
if(T&&T<cnt)
{
cnt=T; // find the smallest one in the alphabet & position
position=i;
}
while(cnt<=1000)
{
Output(T,cnt,position);
position=127;
cnt++;
}
cout<<endl;
}
}[/cpp]
AC makes me feels good,
But WA makes me thinks hard.
But WA makes me thinks hard.
-
- Experienced poster
- Posts: 136
- Joined: Tue Apr 01, 2003 6:59 am
- Location: Jakarta, Indonesia