HDOJ 1282 回文数猜想

来源:互联网 发布:数据共享与交换 编辑:程序博客网 时间:2024/06/05 12:04

HDACM1282

水……

import java.util.Scanner;public class Main{    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        while (sc.hasNext()) {            int n = sc.nextInt();            int count = 0;            String str = n+"";            while (n != rollBack(n)) {                count++;                n += rollBack(n);                str =str +"--->"+n;            }            System.out.println(count);            System.out.println(str);        }    }    public static int rollBack(int num){        char c[] = (""+num).toCharArray();        int left = 0;        int right = c.length-1;        while(left <= right){            char ch = c[left];            c[left] = c[right];            c[right] = ch;            left++;            right--;        }        String str = "";        for (int i = 0; i < c.length; i++) {            str += c[i];        }        return Integer.parseInt(str);    }}
原创粉丝点击