Hangzhou Electric HDU 1266 Reverse number

Source: Internet
Author: User

Reverse number Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 5763 Accepted Submission (s): 2643


Problem Descriptionwelcome to 2006 ' 4 Computer College programming contest!

Specially, I give my best regards to all freshmen! You is the future of HDU acm! And now, I must the that ACM problems is always don't so easy, but, except this one ... ha-ha!

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

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

Outputfor Each test case, you should the output its reverse number, one case per line.

Sample Input
312-121200

Sample Output
21-212100

Authorlcy
Source

HDU 2006-4 Programming Contest

It's a quick and convenient thing to do with string .... ~ ~ ~, the question should be submitted to AC;

AC Code:

#include <iostream> #include <string>using namespace Std;int main () {int t,n;string str;while (cin>>t) {for (int i=0;i<t;i++) {cin>>str;int len=str.size (), int k=len-1;if (str[0]!= '-') {for (int i=len-1;i>=0;i-- if (str[i]!= ' 0 ') {k=i;break;} for (int j=k;j>=0;j--) cout<<str[j];for (int p=0;p<len-1-k;p++) Cout<<0;cout<<endl;} Else{str.erase (0,1);cout<< '-'; for (int i=len-1-1;i>=0;i--) if (str[i]!= ' 0 ') {k=i;break;} for (int j=k;j>=0;j--) cout<<str[j];for (int p=0;p<len-2-k;p++) Cout<<0;cout<<endl;}}} return 0;}


Hangzhou Electric HDU 1266 Reverse number

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.