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
asif_rahman0
Experienced poster
Posts: 209 Joined: Sun Jan 16, 2005 6:22 pm
Post
by asif_rahman0 » Mon Jun 06, 2005 3:59 am
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.
jasiu--
New poster
Posts: 3 Joined: Tue May 31, 2005 8:49 pm
Post
by jasiu-- » Mon Jun 06, 2005 12:42 pm
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
Piotr
New poster
Posts: 2 Joined: Mon Jun 13, 2005 2:12 pm
Post
by Piotr » Mon Jun 13, 2005 2:20 pm
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.
GeorgeBusch
New poster
Posts: 10 Joined: Fri Jun 10, 2005 5:30 pm
Post
by GeorgeBusch » Mon Jun 13, 2005 11:36 pm
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.
thirddawn
New poster
Posts: 9 Joined: Sat Oct 15, 2005 4:41 am
Post
by thirddawn » Tue Nov 22, 2005 6:23 pm
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
tan_Yui
Experienced poster
Posts: 155 Joined: Sat Jul 10, 2004 12:41 am
Post
by tan_Yui » Tue Nov 22, 2005 8:40 pm
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 :
Output :
And, see this to avoid PresentationError.
A blank line should separate each set of output.
Best regards.
beloni
Learning poster
Posts: 66 Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil
Post
by beloni » Fri Jan 06, 2006 3:48 pm
try to write your code in C
mamun
A great helper
Posts: 286 Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:
Post
by mamun » Fri Jan 06, 2006 7:37 pm
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.
ashikzinnatkhan
New poster
Posts: 8 Joined: Wed Jan 25, 2006 6:25 pm
Location: Dhaka, Bangladesh
Post
by ashikzinnatkhan » Wed Jan 25, 2006 6:41 pm
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.
Ashik
tWd2
New poster
Posts: 1 Joined: Wed Jan 25, 2006 6:53 pm
Post
by tWd2 » Wed Jan 25, 2006 7:10 pm
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.
mamun
A great helper
Posts: 286 Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:
Post
by mamun » Wed Jan 25, 2006 9:41 pm
In several places you're trying to access a[200] where size of a is 200.
helloneo
Guru
Posts: 516 Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
Post
by helloneo » Thu Jan 26, 2006 3:25 am
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..
Ankur Jaiswal
New poster
Posts: 31 Joined: Sat Apr 01, 2006 6:24 am
Contact:
Post
by Ankur Jaiswal » Sat Apr 01, 2006 8:47 pm
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?
serur
A great helper
Posts: 251 Joined: Thu Feb 23, 2006 11:30 pm
Post
by serur » Sun Apr 02, 2006 4:51 pm
Try to use multifield sorting( if you didnt do that already) - this being the most advanced algo for problems such these.
smartNET
New poster
Posts: 2 Joined: Fri Apr 14, 2006 12:05 am
Post
by smartNET » Fri Apr 14, 2006 12:11 am
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;
}
}