ibrahim wrote:
if(flag!=0)
printf("\h"); // \n ??
Dear lonelyone, It's my typing mistake.
Code: Select all
#include<stdio.h>
void bubbleSort(int *table,int *index,int n)
{
int i,j,t;
for(i=1;i<n-1;i++)
for(j=2;j<=n-1;j++)
if(table[j]>table[j-1])
{
table[j]=table[j]+table[j-1];
table[j-1]=table[j]-table[j-1];
table[j]=table[j]-table[j-1];
index[j]=index[j]+index[j-1];
index[j-1]=index[j]-index[j-1];
index[j]=index[j]-index[j-1];
}
}
main()
{
int table[129],index[129],copy_table[129];
int i;
char ch,first;
int flag=0;
while(scanf("%c",&first)!=EOF)
{
if(flag!=0)
printf("\n");
flag=1;
for(i=1;i<129;i++)
{
table[i]=0;
index[i]=i;
}
table[(int)first]++;
while((ch=getchar())!='\n')
table[(int)ch]++;
for(i=0;i<129;i++)
copy_table[i]=table[i];
bubbleSort(copy_table,index,129);
for(i=129-1;i>=1;i--)
if(table[index[i]]!=0 && index[i]>=32 && index[i]<=128)
printf("%d %d\n",index[i],table[index[i]]);
}
}
ya~
i tried, but it still failed..
it's output just like following message...
Code: Select all
123
51 1
50 1
49 1
456
<==this is a blank line
54 1
53 1
52 1
789
<==this is a blank line
57 1
56 1
55 1
abc
<==this is a blank line
99 1
98 1
97 1
|<==the input cursor
but it should like below...
you could see the differences between them...
Code: Select all
123
51 1
50 1
49 1
<==this is a blank line
456
54 1
53 1
52 1
<==this is a blank line
789
57 1
56 1
55 1
<==this is a blank line
abc
99 1
98 1
97 1
|<==the input cursor
so...in first input, a blank line should be put after the output..
next, always put a blank line before the input...
but my program is hard to do so..
as you can see, i read a character first...
and after read, put a new line before the output...
that's the problem..
so, there's a solution, and i use getch() of conio.h...
cause, it can read a character and not do anything,
it means, no character could appear in the screen,
and then i could tell this character is equal to NULL or not,
if not then i put a charater and read following message...
but acm online judge can't accept conio.h, because it's not
ANSI standard...
please help me solve this problem...
thank to ibrahim and Mohammad Mahmudur Rahman