HDOJ 1266 Reverse Number(数字反向输出题)
Problem Description 
Welcome to 2006’4 computer college programming contest!
Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM problems are always not so easy, but, except this one… Ha-Ha!
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 should output its reverse number, one case per line.
Sample Input 
3 
12 
-12 
1200
Sample Output 
21 
-21 
2100
注意:前导0的情况! 
例: 
输入: 
3 
-0012560020 
00000 
00205 
输出为: 
-2006521 
0 
502
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            String str = sc.next();
            int instr = Integer.parseInt(str);
            //System.out.println(instr);
            str = Integer.toString(instr);
            //System.out.println(str);
            if (str.charAt(0) == '-') {
                System.out.print("-");
                int k = 0;
                boolean isOne=false;
                //System.out.println(str.length()+"aaa");
                for (int i = str.length() - 1; i >= 1; i--) {
                    //System.out.println("a:  "+str.charAt(i));
                    if(str.charAt(i)!='0'&&!isOne){
                        //System.out.println("++ "+str.charAt(i));
                        isOne=true;
                    }
                    if (isOne) {
                        System.out.print(str.charAt(i));
                        k++;
                    }
                }
                for (int i = 1; i < str.length() - k; i++) {
                    System.out.print(0);
                }
                System.out.println();
            } else {
                int k = 0;
                boolean isOne=false;
                for (int i = str.length() - 1; i >= 0; i--) {
                    if(str.charAt(i)!='0'&&!isOne){
                        isOne=true;
                    }
                    if (isOne) {
                        System.out.print(str.charAt(i));
                        k++;
                    }
                }
                for (int i = 0; i < str.length() - k; i++) {
                    System.out.print(0);
                }
                System.out.println();
            }
        }
    }
}
HDOJ 1266 Reverse Number(数字反向输出题)的更多相关文章
- hdu 1266 Reverse Number
		
题目 一道水题,但是超时了几次(Time Limit Exceeded) 题中说:then n 32-bit integers follow.私以为可以用int来做,结果就一直超时,博客之,发现全是用 ...
 - 水题 HDOJ 4727 The Number Off of FFF
		
题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...
 - Reverse Key Indexes反向索引
		
Reverse Key Indexes反向索引A reverse key index is a type of B-tree index that physically reverses the by ...
 - reverse(两种反向生成url django原生形式和rest_framework中版本的形式)
		
reverse(两种反向生成url django原生形式和rest_framework中版本的形式) views.py from django.shortcuts import render,Http ...
 - Python Number(数字) Ⅰ
		
Python Number(数字) Python Number 数据类型http://www.xuanhe.net/用于存储数值. 数据类型是不允许改变的,这就意味着如果改变 Number 数据类型的 ...
 - javaScript中Number数字类型方法入门
		
前言 Number和Math都属于JavaScript中的内置对象,Number数字类型作为基础数据类型,我们在开发过程中会经常用到,包括数字精度的格式化,还有字符串转换成数字等操作. Number数 ...
 - HDOJ 1755 - A Number Puzzle 排列数字凑同余,状态压缩DP
		
dp [ x ] [ y ] [ z ] 表示二进制y所表示的组合对应的之和mod x余数为z的最小数... 如可用的数字为 1 2 3 4...那么 dp [ 7 ] [ 15 ] [ 2 ] = ...
 - javascript类型系统——Number数字类型
		
× 目录 [1]定义 [2]整数 [3]浮点数[4]科学记数[5]数值精度[6]数值范围[7]特殊数值[8]转成数值[9]实例方法 前面的话 javascript只有一个数字类型,它在内部被表示为64 ...
 - js中Number数字数值运算后值不对
		
问题: 37.5*5.5=206.08 (JS算出来是这样的一个结果,我四舍五入取两位小数) 我先怀疑是四舍五入的问题,就直接用JS算了一个结果为:206.08499999999998 怎么会这样,两 ...
 
随机推荐
- 高级进阶DB2(第2版)——内部结构、高级管理与问题诊断
			
<高级进阶DB2(第2版)——内部结构.高级管理与问题诊断> 基本信息 作者: 牛新庄 出版社:清华大学出版社 ISBN:9787302323839 上架时间:2013-7-3 出版 ...
 - Swift开发语法
			
Swift开发入门 简介 Swift 语言由苹果公司在 2014 年推出,用来撰写 OS X 和 iOS 应用程序 2014 年,在 Apple WWDC 发布 历史 2010 年 7 月,苹果开发者 ...
 - intellij安装Scala及Python插件
			
1.下载intellij及Scala和Python插件 intellij的下载地址:https://www.jetbrains.com/idea/download/#section=windows S ...
 - LA 6450 Social Advertising
			
[题目] 给一个无向图,每当对某个点操作,该点以及与该点相连的点都获得标记,问标记所有点至少需要操作多少次 输入 第一行为T,表示测试数据组数 每组测试数据第一行为n(1<=n<=20)表 ...
 - 拓扑排序 HDU1285
			
这个题是个模板题,可以直接用拓扑排序的模板来做, AC代码 #include <stdio.h> #include<iostream> #include <string. ...
 - 作为iOS开发者不得不follow的52人
			
对于每位iOS开发者来说,Twitter是个获得最新iOS开发技术和相关信息的好地方.如果你刚好有Twitter账户,可以关注以下为你推荐的该领域内的52个优秀人物. 1.Tim Cook 这位无需多 ...
 - jquery ajax 跨域处理
			
今天使用JQuery Ajax 在本地电脑获取远程服务器数据的时候,发现使用$.ajax,$.getJSON,$.get这些都没有反应,后来再统一个网站下测试了一下,代码写得没有问题.后来想了想好想, ...
 - colorful-记录好看的颜色
			
p { float: left; width: 100px; height: 100px; border: 1px solid black; margin: 5px; text-align: cent ...
 - pl/sql的工具导入和代码导入
			
工具导入:在导入的文件中添加导入工具.导入imp:F:\app\Administrator\product\11.1.0\db_1\BIN\imp.exe导出exp:F:\app\Administra ...
 - Windows Server 2008关闭internet explorer增强的安全配置
			
服务器系统要求很高的安全性,所以微软给ie添加了安全增强.这就使得ie在Internet区域的安全级别一直是最高的,而且无法进行整体调整. 关闭IE SEC服务器系统要求很高的安全性,所以微软给ie添 ...