Question 9: Reverse Number

Source: Internet
Author: User

[Plain] Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:
1. The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21;
2. The reverse number of a negative integer is negative, for example, reverse (-12) =-21;
3. The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.
 
Input
 
Input file contains multiple test cases. There is a positive integer n (n <100) in the first line, which means the number of test cases, and then n 32-bit integers follow.
 
Output
 
For each test case, you shoshould output its reverse number, one case per line.
 
Sample Input
 
 
3
12
-12
1200
 
Sample Output
 
 
21
-21
2100

Give you an integer; your task is to output its reverse number. Here, reverse number is defined as follows:
1. The reverse number of a positive integer ending without 0 is general reverse, for example, reverse (12) = 21;
2. The reverse number of a negative integer is negative, for example, reverse (-12) =-21;
3. The reverse number of an integer ending with 0 is described as example, reverse (1200) = 2100.

Input

Input file contains multiple test cases. There is a positive integer n (n <100) in the first line, which means the number of test cases, and then n 32-bit integers follow.

Output

For each test case, you shoshould output its reverse number, one case per line.

Sample Input


3
12
-12
1200

Sample Output


21
-21
2100
[Plain] <PRE class = plain name = "code"> # include <stdio. h>
 
Int main ()
{
Int I;
Int j;
Int n;
Int tab; // indicates whether there is zero at the end of the tag.
Int num;
Int flag; // indicates whether the flag is a positive or negative number.
Int count;
Int array [100]; // stores values.
 
Scanf ("% d", & n );
While (n --)
{
Scanf ("% d", & num );

J = 0;
Tab = 1; // assume there is zero at the end
Flag = 1; // positive number is 1
Count = 0;
If (num <0)
{
Flag = 0; // negative
Num =-1 * num;
}
 
While (num)
{
If (num % 10 = 0 & tab! = 0)
{
Count ++; // calculates the number of zeros.
}
Else
{
Array [j ++] = num % 10;
Tab = 0;
}
Num/= 10;
}
 
If (flag = 0)
{
Printf ("-");
}
 
For (I = 0; I <j; I ++)
{
Printf ("% d", array [I]);
}

For (I = 0; I <count; I ++) // print the number of zeros at the end
{
Printf ("0 ");
}
If (n> 0)
{
Printf ("\ n ");
}
}
 
Return 0;
}
</PRE> <BR>
<BR>
<PRE> </PRE>
<P> </P>
<PRE> </PRE>
<PRE> </PRE>

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.