Page 7 of 16

Hello

Posted: Mon Jun 06, 2005 3:59 am
by asif_rahman0
Hello sanbinHo I'm not a good helper and also not a good programmer.I've also solved this problem with the help of forum.Anyway,I've just run a buuble sort to print the output in the ascending order of the frequencies.And create three int arrays to put the values and frequencies and the sorted value.
Anyway,Ur code seems me as a bit complex.Hope I can help u little bit.And U can try to solve the problem with my procedure. :)

Posted: Mon Jun 06, 2005 12:42 pm
by jasiu--
i see you are counting letters x, for which 32 < x <= 128. as far as i remember, it should be 32 <= x < 128. perhaps this will help. regards,

jasiu

10062. Why got WA??

Posted: Mon Jun 13, 2005 2:20 pm
by Piotr
Could you tell me what is wrong with this problem. Please help me!!! Thank you!!

program p10062;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
t: array[0..256] of integer;
i,min,liczba: integer;
b: boolean;
s: ansistring;

begin
while not eof(input) do
begin

readln(s);
if s<>'' then
begin
for i:=1 to length(s) do
inc(t[ord(s)]);



repeat
min:=1001;
b:=true;
for i:=33 to 128 do
if (t<=min)and(t<>0) then
begin
min:=t;
liczba:=i;
end;

writeln(liczba,' ',min);

t[liczba]:=0;
for i:=33 to 128 do
if t<>0 then b:=false;

until b=true;
writeln;
end;
end;
end.

Posted: Mon Jun 13, 2005 11:36 pm
by GeorgeBusch
Hello, i just found out your mistake.
It is really really sad mistake:
In the statement
for i:=33 to 128 do
you should begin with 32, because the first 32 chars are 0..31!!!!

i got your code acc but with PE cause you print a newline after last case.

10062 WA...Need help

Posted: Tue Nov 22, 2005 6:23 pm
by thirddawn

Code: Select all

#include <stdio.h>
#include <string.h>

int main(){
	char word[1001];
	int number[1001];
	int i,max,j;
	while (scanf("%s",&word)==1){
		max = strlen(word);
		for (i = 0; i < 257;i++)
			number[i] =0;
		for (i = 0; i < max;i++)
			number[word[i]] = number[word[i]] + 1;
		for (j = 1; j <=max ; j ++){
			for (i = 256; i >=0 ;i--){
				if (number[i] == j)
					printf("%d %d\n",i,number[i]);
			}
		}
	}
}
My code are as above

I get passed all the sample input and the input which is offered on this board...but I can't figure out why I always get WA...

Thanks for helping :P

Re: 10062 WA...Need help

Posted: Tue Nov 22, 2005 8:40 pm
by tan_Yui
Your code should handle the space character as one character.
To avoid this matter, it's easy to use gets() function instead of scanf() for implementation.

Input :

Code: Select all

a a a
Output :

Code: Select all

32 2
97 3
And, see this to avoid PresentationError. :)
A blank line should separate each set of output.
Best regards.

Posted: Fri Jan 06, 2006 3:48 pm
by beloni
try to write your code in C

Posted: Fri Jan 06, 2006 7:37 pm
by mamun
I don't remember but I think once I found in the forum that there contains characters of ASCII greater than 128. Search the forum. That's what you should do before posting your question.

10062, Tell me the frequencies, PE, please help

Posted: Wed Jan 25, 2006 6:41 pm
by ashikzinnatkhan
Here is my code:



#include <stdio.h>



void main()
{
unsigned char ch ;
int i , j , start = 0;
int ascii[96][2] , temp0 , temp1 ;


for(i=0 ; i<96 ; i++)
{
ascii[0] = i+32 ;
ascii[1] = 0 ;
}

while( (char) ( ch = getchar() ) != EOF )
{

if((ch == '\n') || (ch == '\r')) start=1;

i = ch;

ascii[i-32][1]++ ;

if(start == 1)
{
for( j=0 ; j<48; j++)
{
temp0 = ascii[j][0];
temp1 = ascii[j][1];

ascii[j][0] = ascii[95-j][0];
ascii[j][1] = ascii[95-j][1];

ascii[95-j][0] = temp0;
ascii[95-j][1] = temp1;


}

for( i=1; i<96 ; ++i)
for(j=95; j>=i; --j)
{
if(ascii[j-1][1] > ascii[j][1] )
{
temp0 = ascii[j-1][0];
temp1 = ascii[j-1][1];

ascii[j-1][0] = ascii[j][0];
ascii[j-1][1] = ascii[j][1];

ascii[j][0] = temp0;
ascii[j][1] = temp1;

}

}


for( i=0; i<96; i++)
{
if(ascii[1] > 0) printf("%d %d\n",ascii[0] , ascii[1] );

}

printf("\n");


start = 0;


for(i=0 ; i<96 ; i++)
{
ascii[0] = i+32 ;
ascii[1] = 0 ;
}


fflush(stdin);


}


}

}









It is giving PE.
I cannot understand why.
Please help me.

10062, Tell me the frequences, RTE, please help

Posted: Wed Jan 25, 2006 7:10 pm
by tWd2
Here is my code:

#include<iostream>
using namespace std;
int main()
{
int a[200];
for(int i=0;i<=200;i++)a=0;
int min=1000,max=0,n,t;
char c;

while(cin.get(c))
{
n=c;
if(cin.fail())return 0;
if(n==10||n==32)
{
if(t==1)
{
for(int i=200;i>=0;i--)
{
if(a<min && a>0 ) min=a;
if(a>max) max=a;
}
for(;min<=max;min++)
for(int i=200;i>=0;i--)
if(a==min)
cout << i+1 << " " << a << endl;
cout<<endl;
}
min=1000;
max=0;
t=0;
for(int i=0;i<=200;i++)
a=0;
}
else if(n>32)
{
a[n-1]++;
t=1;
}
}
}

I've tried many times but it is still Runtime Error.
Please help me.

Posted: Wed Jan 25, 2006 9:41 pm
by mamun
In several places you're trying to access a[200] where size of a is 200.

Posted: Thu Jan 26, 2006 3:25 am
by helloneo
there shouldn't be a blank line at the end of output..


you're output is like ths..

Code: Select all

67 1
66 2
65 3

49 1
50 2
51 3

52 2
51 4
48 4
50 5
49 5
        <---- delete this line..

10062

Posted: Sat Apr 01, 2006 8:47 pm
by Ankur Jaiswal
I am using the straightforward algo to solve this problem. However I am using an array of size just 97 (for storing the values from 32 to 128 as given in the question). Is this the problem. I also understood the question as follows : if the frequency of two or more characters is the same, then print the character with the greater ASCII value first. Is this the problem? If not any one of the above mentioned, then what else can be the problem?

Tell him the frequencies and have done with it!

Posted: Sun Apr 02, 2006 4:51 pm
by serur
Try to use multifield sorting( if you didnt do that already) - this being the most advanced algo for problems such these.

10062 HELP ME PLEASE

Posted: Fri Apr 14, 2006 12:11 am
by smartNET
this is my code , can you help me to find my wrong please ????
C++

Code: Select all

#include<iostream.h>
#include<string.h>
 char tabla[1000][1000];
long int resultados[1000][2];

struct tablita{
	int simbolo[1000];
	int cantidad[1000];
};
tablita final[1000];
void ordena(int);
void cuenta(int);
void main()
{
	long int y,local;
	y=10;
   for( local=0;local<10;local++)
   {
	   cout<<local;cin.getline(tabla[local],1000);
   }
 
   
    ordena(local);

	for(int v=0;v<y;v++)
	{
		int w;
		w=strlen(tabla[v]);
		for(int h=0;h<w;h++)
		{
		//	cout<</*v<<h<<" "<<*/tabla[v][h];
		}
		//cout<<endl;
	}
	cuenta(y);


}

void ordena(int a)
{
	for(int u=0;u<a;u++)
	{
		int n;	
		n=strlen(tabla[u]);
	//	cout<<"estado de u "<<u<<endl;

		int i,j;
		char temp;
	for(i=1;i<n;i++)
	{
		for(j=n-1;j>=i;j--)
		{
			if(tabla[u][j-1]>tabla[u][j])
			{
				temp=tabla[u][j-1];
				tabla[u][j-1]=tabla[u][j];
				tabla[u][j]=temp;
			}
		}
	}
	}
}

void cuenta(int y)
{
	int dir[1000][2];
	for(int i=0;i<y;i++)
	{
		int c,es=0;
		
		c=strlen(tabla[i]);
		for(int b=0;b<c;b++)
		{
			dir[i][0]=i;
			if (b==0)
			{
				if((tabla[i][b]>=32) &&  (tabla[i][b]<=128))
				{
				final[i].simbolo[es]=tabla[i][b];
				final[i].cantidad[es]=1;
				dir[i][1]=es;
				}
				
				
			}
			if (b>0)
			{
				if((tabla[i][b]>32) &&  (tabla[i][b]<128))
				{
				if(tabla[i][b]==tabla[i][b-1])
				{
					final[i].cantidad[es]++;
				

				}
				if(tabla[i][b]!=tabla[i][b-1])
				{
					es++;
					final[i].simbolo[es]=tabla[i][b];
					final[i].cantidad[es]=1;
					
					dir[i][1]=es;
				}
				}
			}
		}
	}

int num,sym,bu,ba;
for(int palabra=0;palabra<y;palabra++)
{

	for(bu=1;bu<dir[palabra][1]+1;bu++)
	{
		for(ba=(dir[palabra][1]);ba>=bu;ba--)
		{
			
		
			if (final[palabra].cantidad[ba-1]>final[palabra].cantidad[ba])
			{
				//cout<<"intercambio "<<final[palabra].cantidad[ba-1]<<" "<<final[palabra].cantidad[ba]<<endl;
				num=final[palabra].cantidad[ba-1];
				sym=final[palabra].simbolo[ba-1];

				final[palabra].cantidad[ba-1]=final[palabra].cantidad[ba];
				final[palabra].simbolo[ba-1]=final[palabra].simbolo[ba];
				
				final[palabra].cantidad[ba]=num;
				final[palabra].simbolo[ba]=sym;
			}
			//cout<<"candidades"<<final[palabra].cantidad[ba-1]<<final[palabra].cantidad[ba];

			if((final[palabra].cantidad[ba-1])==(final[palabra].cantidad[ba]))
			{
			int app;
			app=final[palabra].simbolo[ba-1];
		//	abb=final[palabra].simbolo[ba];
			final[palabra].simbolo[ba-1]=final[palabra].simbolo[ba];
			final[palabra].simbolo[ba]=app;
		

			
			}
		
		}
	}
}



	

for(int pala=0;pala<y;pala++)
{
	for(int cont=0;cont<dir[pala][1]+1;cont++)
	{
		cout<<final[pala].simbolo[cont]<<" "<<final[pala].cantidad[cont]<<endl;
	}
	cout<<endl;

}

}