题目57
来源:互联网 发布:淘宝买什么东西比较好 编辑:程序博客网 时间:2024/04/28 23:08
#include<stdio.h>#include<math.h>#include<stdlib.h>void swap1(int *p, int *q);void swap2(int *p, int *q);int main(){int x, m, i, y, s, z;int a, b, c, d;scanf("%d", &m);getchar();while(m--){scanf("%d", &x);getchar();i = 0;if(x == 6174){printf("1\n");getchar();continue; } while(1){a = x%10;b = (x%100-a)/10;c = (x%1000-b*10-a)/100;d = (x-c*100-b*10-a)/1000;swap1(&a, &b);swap1(&a, &c);swap1(&a, &d);swap1(&b, &c);swap1(&b, &d);swap1(&c, &d);y = 1000*a+100*b+10*c+d;swap2(&a, &b);swap2(&a, &c);swap2(&a, &d);swap2(&b, &c);swap2(&b, &d);swap2(&c, &d);z = 1000*a+100*b+10*c+d;x = y - z;i++;if(x == 6174){break; } }printf("%d\n", i+1);}return 0; }void swap1(int *p, int *q){int t;if(*p < *q){t = *p;*p = *q;*q = t;}}void swap2(int *p, int *q){int t;if(*p > *q){t = *p;*p = *q;*q = t;}}
0 0
- 题目57
- 题目57-6174问题
- 题目57 6174问题
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- 题目
- SpringMVC+FastJson 自定义日期转换器
- 在Linux下安装python
- Android学习之图片加载库Glide
- Ajax使用jQuery与后台交互
- 传感器系列之4.2气压传感器
- 题目57
- 用python实现从1加到100的三种方法: for循环,while循环,导入模块法
- 1004-D专题三
- 第一次使用 IntelliJ IDEA写一个html动作
- 数据库视频总结(一)
- 练习三 1017
- 【Android工程师】自定义控件 - ToggleView(开关状态选择器)
- CSS
- (Leetcode 99) Recover Binary Search Tree(恢复二叉排序树BST)