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 |
用next_permutation,能过样例但是一直WA,要死要死。。。#include <iostream> #include <algorithm> #include <cstdio> #include <string> using namespace std; int main() { int len,flag; freopen("input.txt","r",stdin); string dict[101],word; len=0; while(1) { cin>>dict[len]; if(dict[len]=="XXXXXX") break; len++; } sort(dict,dict+len); //cout<<"1"<<endl; while(1) { cin>>word; flag=0; if(word=="XXXXXX") break; if(word.size()==1) { for(int i=0; i<len; i++) { if(dict[i].size()!=word.size()) continue; if(word==dict[i]) { cout<<dict[i]<<endl; flag++; } } } else if(word.size()==2) { for(int i=0; i<len; i++) { if(dict[i].size()!=word.size()) continue; if(word==dict[i]) { cout<<dict[i]<<endl; flag++; } } reverse(word.begin(),word.end()); for(int i=0; i<len; i++) { if(dict[i].size()!=word.size()) continue; if(word==dict[i]) cout<<dict[i]<<endl; flag++; } } else if(word.size()>=3) { sort(word.begin(),word.end()); while(next_permutation(word.begin(),word.end())) for(int i=0; i<len; i++) { if(dict[i].size()!=word.size()) continue; if(word==dict[i]) { cout<<dict[i]<<endl; flag++; } } } if(flag==0) cout<<"NOT A VALID WORD"<<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