"Recursive and recursive" phone number

Source: Internet
Author: User

"Recursive and recursive" phone number The title describes a number of English letters written below each number on the telephone. The distribution is as follows:
1~abc
2~def
3~ghi
4~ikl
5~mn
6~opq
7~rst
8~uvw
9~xyz
Now given a word list and a string of numbers, please use the words in the word list to translate this password.

Enter the first behavior a positive integer N indicates the number of words in the Word table (n≤100);
Second act a string of numbers not exceeding 100, indicating the password;
The next n rows, each line of a word with a length of not more than 20, represent the Word table.

Output only one line, the translated text, if the password can not be translated, then output "No solutions!", if the password has a variety of translations, the output can be any. Sample input
873373711664thishsthisisbabook
Sample output
Thi Shs b Boo k

Analysis:
Map words to numbers first, then violent match
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineVI vector<int>#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=1e2+Ten;Const intdis[][2]={0,1,-1,0,0,-1,1,0};using namespacestd;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p%mod;p=p*p%mod;q>>=1;}returnF;}stringA[MAXN],F,B[MAXN];intLen[maxn],len1,n;stringCheckstringAintl) {    stringp;  for(intI=0; i<l;i++)    {        if(a[i]=='a'|| a[i]=='b'|| a[i]=='C') p+='1'; Else if(a[i]=='D'|| a[i]=='e'|| a[i]=='F') p+='2'; Else if(a[i]=='g'|| a[i]=='h'|| a[i]=='I') p+='3'; Else if(a[i]=='J'|| a[i]=='k'|| a[i]=='L') p+='4'; Else if(a[i]=='m'|| a[i]=='N') p+='5'; Else if(a[i]=='P'|| a[i]=='Q'|| a[i]=='o') p+='6'; Else if(a[i]=='R'|| a[i]=='s'|| a[i]=='T') p+='7'; Else if(a[i]=='u'|| a[i]=='v'|| a[i]=='W') p+='8'; Else if(a[i]=='x'|| a[i]=='y'|| a[i]=='Z') p+='9'; }    returnp;}voidDfsintNowstringans) {    if(NOW==LEN1) {COUT&LT;&LT;ANS.SUBSTR (1, Ans.length ()-1) <<endl;exit (0);} Else    {         for(intI=0; i<n;i++)if(Now+len[i]<=len1&&b[i]==f.substr (Now,len[i])) DFS (now+len[i],ans+" "+A[i]); return; }}intMain () {inti,j,m,k,t; scanf ("%d",&N); CIN>>f;len1=f.length (); Rep (I,0, N-1) Cin>>a[i],len[i]=a[i].length (), b[i]=check (a[i],len[i]); DFS (0,""); Puts ("No solutions!"); //System ("pause");    return 0;}



"Recursive and recursive" phone number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.