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> #include <string> using namespace std; int check(string word,string dic);//检查两个单词是否相等 void sortString(string dic[],int dic_num);//对输入的单词进行排序 int main () { string dic[110]; string word[110]; int dnum=0; int wnum=0; while(1) { cin>>dic[dnum]; if(dic[dnum]=="XXXXXX") break; else dnum++; } sortString(dic,dnum); int p; for(p=0;p<dnum;p++) cout<<dic[p]<<endl; while(1) { cin>>word[wnum]; if(word[wnum]=="XXXXXX") break; else wnum++; } int k,i,j; for(i=0;i<wnum;i++) { k=0; for(j=0;j<dnum;j++) { if(check(word[i],dic[j])==1) { cout<<dic[j]<<endl; k++; } } if(k==0) cout<<"NOT A VALID WORD"<<endl; else cout<<"******"<<endl; } return 0; } int check(string word,string dic) { int len1=word.length(); int len2=dic.length(); if(len1!=len2) return -1; else { int mark[10]={0}; int i; for(i=0;i<len1;i++) { int pos=0; for(pos=0;pos<len1;pos++) { if(mark[pos]==0&&word[i]==dic[pos]) { mark[pos]=1; break; } } if(pos==len1) return -1; } return 1; } } void sortString(string dic[],int dic_num) { int i,j; int pos; for(i=0;i<dic_num-1;i++) { for(j=i+1;j<dic_num;j++) { pos=0; int len1=dic[i].length(); int len2=dic[j].length(); while(pos<len1&&pos<len2) { if(dic[i][pos]>dic[j][pos]) { swap(dic[i],dic[j]); break; } else if(dic[i][pos]==dic[j][pos]) pos++; else break; } if(pos==len1) ; if(pos==len2) swap(dic[i],dic[j]); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator