当前位置: 代码迷 >> 综合 >> HDOJ 1266 Reverse Number
  详细解决方案

HDOJ 1266 Reverse Number

热度:86   发布时间:2023-10-21 19:37:16.0

HDACM1266

注意细节:只有末尾的0才是特殊的

import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();while(n-->0){int num = sc.nextInt();String str = "";boolean isNegative = false;if (num<0) {isNegative = true;num = -num;}if (num == 0) {System.out.println(0);continue;}boolean isEnd = true;while (num>0) {if (num%10==0&&isEnd) {str += "0";num /= 10;continue;}if (isNegative) {System.out.print("-");isNegative = false;}isEnd = false;System.out.print(num%10);num /= 10;}System.out.println(str);}}
}
  相关解决方案