poj2418(水题,qsort)

来源:互联网 发布:淘宝超重武者 编辑:程序博客网 时间:2024/05/14 18:43

//暴力解之
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char strName[1000001][31];


int cmp( const void *a,const void *b)
{
     return ( strcmp( (char *)a, (char *)b ) );
}


int main()
{
    int i=0,count=1,j;


    while( gets(strName[i]) )
           i++;


    qsort(strName,i,31,cmp);  //系统快排


     for(j=0;j<i;j++)
    {
            if( strcmp(strName[j],strName[j+1])==0 )
                count++;
            else
            {          
                printf("%s %.4f/n",strName[j],(float)count*100/i);
                count=1;
            }
    }


    return 0;
}

原创粉丝点击