Zzuli oj 1167 reverse number (pointer topic), zzulioj

Source: Internet
Author: User

Zzuli oj 1167 reverse number (pointer topic), zzulioj
Description

If you are given an integer, this number may be very large (up to 100 digits). Can you find its reverse number?
The reverse number is defined as follows:
1. There is no zero integer at the end, and its reverse number is the reverse output of various numbers;
2. The reverse number of a negative number is still negative;
3. There is a 0 integer at the end, and its reversal number is like the following example:
Reverse (1, 1200) = 2100
Reverse (-56) =-65
Define and use the following functions:
Void reverse (char * str)
{
// Function to find the reverse number of str and store it in str.
}

Input

Enter a long integer str with no more than 100 digits. The input integer does not contain leading 0.

Output

Returns the reverse number of str. The output occupies one row.

Sample Input-123456789000 Sample Output-987654321000
1 # include <iostream> 2 # include <cstdio> 3 # include <algorithm> 4 # include <cstring> 5 using namespace std; 6 7 int main (int argc, char ** argv) 8 {9 char str [101]; 10 int I, flag = 0, count = 0; 11 gets (str ); 12/* output negative number */13 if (str [0] = '-') 14 printf ("-"); 15/* inverted output */16 for (I = strlen (str)-1; I> = 1; I --) 17 {18 if (str [I] = '0' & flag = 0) 19 {20 count ++; // count the number of zeros 21 continue; // skip 22} 23 if (str [I]! = '0' | flag! = 0) 24 {25 printf ("% c", str [I]); 26 flag = 1; // indicates whether the ending number is 0 27} 28 29} 30 if (str [0]! = '-') 31 printf ("% c", str [0]); // output the first number 32/* output the skipped 0 */33 for (I = 1; I <= count; I ++) 34 printf ("0 "); 35 return 0; 36}

 

Related Article

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.