| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:哪位大侠帮忙看一下,TLE,到底是怎么回事.先谢谢了!!In Reply To:哪位大侠帮忙看一下,TLE,到底是怎么回事.先谢谢了!! Posted by:catoran at 2006-07-17 21:33:26 > #include<stdio.h>
> #include<stdlib.h>
> #include<string.h>
>
> char name[1000001][31];
> int sort_fun(const void *a,const void *b);
>
> void main(){
>
> char sname[10000][31];
> float sname_fre[10000];
> int i=0,j=0,n=0,count=0;
> while((int)(gets(&name[i][0]))!=EOF){
> i++;
> n++;
> }
>
> printf("n=%d\n",n);
>
> qsort((void *)name,n+1,sizeof(name[0]),sort_fun);
>
> count=1;
> for(i=0;i<n-1;i++){
> if(!strcmp(&name[i][0],&name[i+1][0])){
> if(i==n-1){
> strcpy(&sname[i][0],&name[i][0]);
> j++;
> strcpy(&sname[i+1][0],&name[i+1][0]);
> j++;
> sname_fre[i]=(float)(100*count)/n;
> count=1;
> sname_fre[i+1]=(float)(100*count)/n;
> count=1;
> }
> else{
> strcpy(&sname[i][0],&name[i][0]);
> j++;
> sname_fre[i]=(float)(100*count)/n;
> count=1;
> }
> }
> else
> count++;
> }
>
> for(i=0;i<j;i++){
> printf("%s %0.4f\n",&sname[i],sname_fre[i]);
> }
> }
>
> int sort_fun(const void *a,const void *b){
> return(strcmp((char*)a,(char*)b));
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator