[ create a new paste ] login | about

Link: http://codepad.org/K3hi1mIC    [ raw code | fork ]

C, pasted on May 7:
#include<stdio.h>
#include<string.h>
#define ARRAY_MAX 1000
#define ASCII_MAX 256
int main(){
        char input[ARRAY_MAX];
        int i,j,temp,flag;
        int ascii[ASCII_MAX]={0},pk[ASCII_MAX]={0};
        while(gets(input)!=NULL){
                for(i=0;input[i]!=0;i++)
                        ascii[input[i]]++;
                for(i=0;i<ASCII_MAX;i++)
                        pk[i] = i;
                for(i=ASCII_MAX-1;i>=0;i--){
                        flag = 0;
                        for(j=i;j>=0;j--){
                                if(ascii[pk[i]] < ascii[pk[j]]){
                                        flag = 1;
                                        temp = pk[j];
                                        pk[j] = pk[i];
                                        pk[i] = temp;
                                }
                        }
                        if(!flag)
                                break;
                }
                for(i=0;i<ASCII_MAX;i++)
                        if(ascii[pk[i]]>0)
                                printf("%d %d\n",pk[i],ascii[pk[i]]);
                printf("\n");
                memset(ascii,0,sizeof(ascii));
                memset(pk,0,sizeof(pk));
                memset(input,0,strlen(input));
        }
        return 0;
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: