首页 > 其他 > 详细

NYOJ题目57 6174问题

时间:2016-09-20 23:50:41      阅读:172      评论:0      收藏:0      [点我收藏+]

技术分享

-----------------------------------------------------

感觉这个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

NYOJ题目57 6174问题

原文:http://www.cnblogs.com/cc11001100/p/5891034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!