1244: Reverse Number

来源:互联网 发布:gdp 知乎 编辑:程序博客网 时间:2024/06/03 07:31


描述

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 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.

输出

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

样例输入

312-121200

样例输出

21-212100

题目来源

http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1244



#include <iostream>using namespace std;int main(){    string s;    int n;    cin>>n;    while(n--)    {        cin>>s;        if(s[0]=='-')            cout<<'-';        int num=0;        bool flag = true;        for(int i = s.size()-1;i>=0;i--)        {            if(s[i]=='0' && flag)                num++;            else if(s[i]!='-')            {                flag = false;                cout<<s[i];            }        }        while(num--)            cout<<'0';        cout<<endl;    }    return 0;}



0 0
原创粉丝点击