Programming US $3.2 phone number corresponds to English letters, US $3.2

Source: Internet
Author: User

Programming US $3.2 phone number corresponds to English letters, US $3.2

This is also a very common question. Many similar questions use the same solution. This question means that the numbers on our mobile phones correspond to English letters, this number may correspond to 3, 4, or 0, so when I enter a string of numbers, you need to give all possible English letters for these numbers.

Speaking of this, I believe you will understand that this is actually a full arrangement, but we need to first give a known condition, that is, the numbers correspond to which letters correspond to a few letters, because we need to make a full arrangement, it is necessary to know a range. Therefore, using the thought of full arrangement, we can easily write the following code:

Function declaration:

/* 3.2 phone number corresponds to the English letter */void DutNumberToAlphabet (int *, int); void DutNumberToAlphabet (int *, int, char *, int, int *);

Source code:

Char c [] [10] = {"", "", "ABC", "DEF", "GHI", "JKL", "MNO", "PQRS ", "TUV", "WXYZ"}; // store the characters int total [10] = {0, 0, 3, 3, 3, 3, 3, 4, 3, 4}; // The total number of characters that each array can represent. void DutNumberToAlphabet (int * number, int size) {if (! Number | size <= 0) return; char * result = new char [size]; int * answer = new int [size]; memset (answer, 0, sizeof (int) * size); DutNumberToAlphabet (number, size, result,/* index */0, answer);} void DutNumberToAlphabet (int * number, int size, char * result, int index, int * answer) {if (index = size) {for (int I = 0; I <size; ++ I) cout <c [number [I] [answer [I]; cout <endl;} else {for (answer [index] = 0; answer [index] <total [number [index]; ++ answer [index]) DutNumberToAlphabet (number, size, result, index + 1, answer );}}




Write the first letter of the phone number in English in uppercase.

No
 
Add English letters to a fixed phone number, such as 0208285259 M

Is there any meaning of transfer?
 

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.