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 |
我没仔细看,里面有一个trap是相同的词按重数算不过只输出一次In Reply To:wa了一个上午,谁能帮我看看,是不是有什么陷阱,我是3次排序做的,每个词排一次,所有词排一次,分组后在排一次,应该是比较简单的吧 Posted by:cpp051300448324 at 2005-05-19 12:04:29 > #include<iostream> > #include<cstring> > #include<algorithm> > #include<fstream> > #define min(a,b) (a<b?a:b) > using namespace std; > struct tag_1{ > char str[50]; //存储的每个词 > char str_cmp[50]; //字典序的这个词 > }; > > struct tag_2{ > tag_1 * p; //分组的首地址 > int size; //分组的长度 > }; > > bool cmp_1(tag_1 s1,tag_1 s2){ > int signal=strcmp(s1.str_cmp,s2.str_cmp); > if(signal!=0)return signal<0; > else return strcmp(s1.str,s2.str)<0; > } > > bool cmp_2(tag_2 s1,tag_2 s2){ > if(s1.size!=s2.size) return s1.size>s2.size; > else return strcmp((s1.p)->str,(s2.p)->str)<0; > } > > > > tag_1 s[30000]; //单词 > tag_2 ss[30000]; //分组 > > int main(){ > ifstream cin("tmp.txt"); > int i=0,j; > int N; > while(cin>>s[i].str){ > strcpy(s[i].str_cmp,s[i].str); > sort(s[i].str_cmp,s[i].str_cmp+strlen(s[i].str_cmp)); > i++; > } > N=i; > int pre=0; > > sort(s,s+N,cmp_1); > ss[0].p=s; > j=1; > for(i=1;i<N;i++){ > if(strcmp(s[i].str_cmp,s[i-1].str_cmp)!=0){ > ss[j].p=s+i; > ss[j-1].size=i-pre; > pre=i; > j++; > } > } > ss[j-1].size=i-pre; > sort(ss,ss+j,cmp_2); > int size=min(j,5); > for(i=0;i<size;i++){ > cout<<"Group of size "<<ss[i].size<<": "; > for(int k=0;k<ss[i].size;k++){ > cout<<(ss[i].p+k)->str<<' '; > } > cout<<'.'<<endl; > } > system("pause"); > return 0; > } > > > > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator