标签:
-----------------------------------------------------
感觉这个OJ题目难度划分很不合理,这道理明明很简单却给了2的难度,而之前难度为0的水题有好多难死个人没做出来让我暗暗觉得自己脑子里都是屎...
把题目描述翻译成人话的意思就是多少次以后这个序列会出现,想明白这一点就比较简单了。
AC代码:
1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main { 5 6 public static void main(String[] args) { 7 8 Scanner sc=new Scanner(System.in); 9 int times=sc.nextInt(); 10 11 while(times-->0) System.out.println(solve(sc.nextInt())); 12 } 13 14 public static int solve(int n){ 15 int res=0; 16 int last=n; 17 while(true){ 18 char cs[]=Integer.toString(n).toCharArray(); 19 Arrays.sort(cs); 20 int min=Integer.parseInt(new String(cs)); 21 StringBuilder sb=new StringBuilder(); 22 int max=Integer.parseInt(sb.append(cs).reverse().toString()); 23 n=max-min; 24 res++; 25 if(n==last) return res; 26 last=n; 27 } 28 } 29 30 }
题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=57
标签:
原文地址:http://www.cnblogs.com/cc11001100/p/5891034.html