Skip to main content

UVa 10062 - Tell me the frequency Solution

UVa 10062 - Tell me the frequency


Description: 

Given a line of text you will have to find out the frequencies of the ASCII characters present in 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.

Input

Several lines of text are given as input. Each line of text is considered as a single input. Maximum length of each line is 1000.

Output

Print the ASCII value of the ASCII characters which are present and their frequency according to the given format below. A blank line should separate each set of output. Print the ASCII characters in the ascending order of their frequencies. If two characters are present the same time print the information of the ASCII character with higher ASCII value first. Input is terminated by end of file.

Sample Input

AAABBC

122333

Sample Output

67 1

66 2

65 3

49 1

50 2

51 3


Solution

#include<stdio.h>
#include<string.h>
int main()
{
    char str[1010],ch;
    int stri[130],i,j,ln=0;
    for(i=0;i<=130;i++)
        stri[i]=0;
    while(gets(str))
    {
        if(ln)
            printf("\n");
        for(i=0;i<strlen(str);i++)
        {
            j=str[i];
            stri[j]++;
        }
        for(i=1;i<=strlen(str);i++)
        {
            for(j=127;j>=32;j--)
                if(stri[j]==i)
                    printf("%d %d\n",j,i);
        }
        ln=1;
        for(i=0;i<=130;i++)
            stri[i]=0;
        str[0]='\0';
    }
    return 0;
}



See More Solution:

Comments

Post a Comment

Populer Article

UVa 10082 - WERTYU Solution

UVa  10082 - WERTYU Description:   A common typing error is to place the  hands on the keyboard one row to the  right of the correct position. So ‘Q’ is  typed as ‘W’ and ‘J’ is typed as ‘K’ and  so on. You are to decode a message typed in this manner. Input Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except  Q, A, Z), or punctuation shown above [except back-quote (‘)]. Keys labelled with words [Tab, BackSp,  Control, etc.] are not represented in the input. Output You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’  keyboard shown above. Spaces in the input should be echoed in the output. Sample Input O S, GOMR YPFSU/ Sample Output I AM FINE TODAY.  Solution #include<stdio.h> int main () { char str[10000], key[]={'`','1','2','3','4','5','6','7','8','9','0', '-','=','...

UVa 10079 - Pizza Cutting Solution

UVa 10079 - Pizza Cutting Description:  When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his intelligence allows him to do something at less physical effort, why should he exert more? He also claims that he always uses his brain and tries to do some work at less effort; this is not his laziness, rather this is his intellectual smartness. Once Ivan was asked to cut a pizza into seven pieces to distribute it among his friends. (Size of the pieces may not be the same. In fact, his piece will be larger than the others.) He thought a bit, and came to the conclusion that he can cut it into seven pieces by only three straight cuts through the pizza with a pizza knife. Accordingly, he cut the pizza in the following way (guess which one is Ivan’s piece): One of his friends, who never believed in Ivan’s smartness, was startled at this intelligence. He thought, if Ivan can do it, why can’t my computer? So he tried to do a similar (but not ex...