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}