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 |
被这题的ac人数带了聋子。。。十分是水。。。 #include <iostream> #include <string> #include <algorithm> using namespace std ; char g[250]; string s ; struct Node { string word, rep ; }seq[1000] ; int n, l; string ret[1000] ; void Init() { g['a'] = g['b'] = g['c'] = '2' ; g['d'] = g['e'] = g['f'] = '3' ; g['g'] = g['h'] = g['i'] = '4' ; g['j'] = g['k'] = g['l'] = '5' ; g['m'] = g['n'] = g['o'] = '6' ; g['p'] = g['q'] = g['r'] = g['s'] = '7' ; g['t'] = g['u'] = g['v'] = '8' ; g['w'] = g['x'] = g['y'] = g['z'] = '9' ; } int cmp(const Node &a, const Node &b) { return a.word < b.word ; } void dfs(int i, int nc) { if(i >= l) { cout << ret[0] ; for(int j = 1 ; j < nc ; j ++) cout << " "<< ret[j] ; cout << "." << endl ; return ; } int l1 ; string tmp ; for(int j = 0 ; j < n ; j ++) { l1 = seq[j].word.length() ; tmp = s.substr(i,l1) ; if( seq[j].rep == tmp) { ret[nc] = seq[j].word ; dfs(i+l1, nc+1) ; } } } int main() { Init() ; while(scanf("%d",&n) && n) { for(int i = 0 ; i < n ; i ++) { cin >> seq[i].word ; seq[i].rep = "" ; for(int j = 0 ;j < seq[i].word.length() ; j ++) seq[i].rep += g[seq[i].word[j]] ; } cin >> s ; l = s.length() ; sort(seq, seq+n, cmp) ; dfs(0, 0) ; 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