Huawei trial (3)

Source: Internet
Author: User

Simple question
Description
Enter a number, output it in reverse order, and output the product of each bit.
Input Description: a positive integer within the int range.
Output Description: two numbers separated by spaces. The first number is the inverted value, and the second number is the product of each digit.
Example: 134
Sample output: 431 12
Solution: simplified and simplified. It is much easier to simply read strings.
PS: You don't need to worry about the meaning of the question here. It is not particularly emphasized that the output is in the format of a number, so there can be a leading 0

 

Void main () {int D; CIN> D; ostringstream OS; OS <D; string S = OS. STR (); int Len = S. size (); int res = 1; int I; for (I = len-1; I> = 0; I --) {cout <s [I]; res * = (s [I]-'0');} cout <''<res <Endl ;}


You can also think that the string type number is directly input, rather than the int type number. In this way, you can omit the code for converting from int to string, and if it starts with 0, it will not be omitted. You need to check the question during the exam.

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.