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 |
虽然是水过了,但还是wa了几次,才发现原来输出来也要按字母顺序#include<iostream> #include<string> using namespace std; struct word { char src[101]; char dest[101]; }; int cmp(const void * A,const void * B) { char ch1 = *(char *)A; char ch2 = *(char *)B; return ch1 >= ch2; } int camp(const void * A,const void *B) { return strcmp((char *)A,(char *)B); } int main() { char ch[101]; word w1[101]; word w2[101]; char result[101][101]={"hello","world","hehe"}; int i,j,k,m; for(i=0;;i++) { cin.getline(ch,20); if(strcmp(ch,"XXXXXX")==0) break; strcpy(w1[i].src,ch); strcpy(w1[i].dest,w1[i].src); //strcpy(result[i],w1[i].src); qsort(w1[i].src,strlen(w1[i].src),sizeof(char),cmp); } //qsort(result,3,sizeof(result[0]),camp); for(j=0;;j++) { cin.getline(ch,20); if(strcmp(ch,"XXXXXX")==0) break; strcpy(w2[j].src,ch); strcpy(w2[j].dest,w2[j].src); qsort(w2[j].src,strlen(w2[j].src),sizeof(char),cmp); } int nums = 0; for(k=0;k<j;k++) { nums = 0; for(m=0;m<i;m++) { if(strcmp(w2[k].src,w1[m].src)==0) { strcpy(result[nums++],w1[m].dest); } } if(nums==0) { cout<<"NOT A VALID WORD"<<endl; } else { qsort(result,nums,sizeof(result[0]),camp); for(int n=0;n<nums;n++) cout<<result[n]<<endl; } cout<<"******"<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator