冒泡排序
来源:互联网 发布:软件测试过程管理 编辑:程序博客网 时间:2024/06/06 03:55
无聊写点代码玩玩
public class Toys {public static void main(String[] args) {for (int i = 0; i < 10000; i++) {if (isResult(i)) {System.out.println(i);}}}// 是否满足目标private static boolean isResult(int source) {int[] b = toArray(source);b = sort(b);int max = maxNumber(b);int min = minNumber(b);return max - min == source ? true : false;}// 将一个整数转为整型数组private static int[] toArray(int source) {int temp[] = new int[10];int i = 0;while (source > 0) {temp[i++] = source % 10;source /= 10;}int result[] = new int[i];for (int k = 0; k < i; k++) {result[k] = temp[k];}return result;}// 冒泡排序private static int[] sort(int[] source) {int result[] = source;for (int j = result.length - 1; j > 0; j--) {for (int k = 0; k < j; k++) {if (result[k] < result[k + 1]) {result[k] ^= result[k + 1];result[k + 1] ^= result[k];result[k] ^= result[k + 1];}}}return result;}// 组成一个整数private static int maxNumber(int[] source) {int max = 0;for (int i = 0; i < source.length; i++) {max *= 10;max += source[i];}return max;}// 组成一个整数private static int minNumber(int[] source) {int min = 0;for (int i = source.length - 1; i >= 0; i--) {min *= 10;min += source[i];}return min;}}有没有bug还没有测,懒人一个!
阅读全文
0 0
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 冒泡排序
- 面试题-前序中序序列重建二叉树
- C# 面向对象(Mp3实例优化 效果图)
- 在xml中使用LayoutAnimationController
- C语言入门
- LintCode python 小白-简单题-2 尾部的0
- 冒泡排序
- TCP 连接断连问题剖析 from IBM developerWorks
- note_cloud--创建笔记本
- sql server总结二
- 中文输入法中的全角和半角的区别
- python进阶
- Redis之在Linux上安装和简单的使用
- PMS Hook
- 框架学习之struts2-02其他配置、异常框架和国际化