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 |
做这种题目一向是义无反顾地超时,大牛们告诉我怎么优化吧#include<iostream.h> #include<string.h> #include<iomanip.h> #include<stdlib.h> char tree[1000000][30]; int count[10000]; int compare(const void *a,const void *b){ return(strcmp((char*)a,(char*)b)); } int cmp(char *a,char *b){ for(int i=0;*(a+i)!='\0'||*(b+i)!='\0';i++) if(*(a+i)!=*(b+i))return 0; return 1; } void main() { int i=0,j=0; while(cin.getline(tree[i],30)) i++; // cout<<i<<endl; qsort(tree,i,sizeof(tree[0]),compare); double num=0; int tem=0; for(j=0;j<i+1;j++){ if(cmp(tree[tem],tree[j])==0){ cout<<tree[tem]<<" "; cout<<setiosflags(ios::fixed); cout<<setprecision(4)<<(100*num/(i))<<endl; tem=j; num=1; continue; } num++; } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator