POJ 1350:Cabric Number Problem
来源:互联网 发布:美国人的零食知乎 编辑:程序博客网 时间:2024/05/19 08:02
题目链接:http://poj.org/problem?id=1350
、
题目翻译:
如果题目给出一个四位数字,而且它的所有位置上的数字不能全部一样,
验证这四个数字组成的最大数和最小数做差后,一直重复这个步骤,可以
得到6174 或 0.
注意:
输入的数字大于4位或小于4位,都要输出No!!
题目太坑了,明明如果给出01234,这样的数字也是可以的,却要判数字大于等于5位就
要输出No.做的时候一直判断是否小于1000,大于等于10000,让我Wa了那么多次了。
AC代码:
#include <iostream>#include <string.h>#include <stdio.h>#include <queue>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;int num1[10];char str[10];void fun(int num){ int time = 0; while(true) { int i = 0; while(num != 0) { num1[i++] = num%10; num = num/10; } sort(num1,num1+i); //从小到大排序 int n1=0,n2=0; for(int j = 0; j < i; j++) { n1 = n1*10 + num1[j]; //最小 n2 = n2*10 + num1[i-1-j]; //最大 } time++; num = n2-n1; printf("%d-%d=%d\n",n2,n1,num); if(num == 6174 || num == 0) break; } printf("Ok!! %d times\n",time);}int main(){ int number; while(~scanf("%s",str)) { if(strcmp(str,"-1") == 0) break; if(strlen(str) != 4) { printf("N=%s:\n",str); printf("No!!\n"); continue; } char t = str[0]; bool flag = false; for(int i = 1; i < 4; i++) { if(t != str[i]) { flag = true; break; } } number = 0; for(int i = 0; i < 4; i++) number = number*10 + str[i]-'0'; if(flag) { printf("N=%s:\n",str); fun(number); } else { printf("N=%s:\n",str); printf("No!!\n"); } } return 0;}
阅读全文
0 0
- poj 1350 Cabric Number Problem
- POJ 1350 Cabric Number Problem
- poj 1350 Cabric Number Problem
- poj 1350 Cabric Number Problem
- poj 1350 Cabric Number Problem
- POJ 1350Cabric Number Problem
- poj-1350Cabric Number Problem
- POJ 1350:Cabric Number Problem
- POJ 1350 Cabric Number Problem
- POJ 1350-Cabric Number Problem
- POJ 1350 Cabric Number Problem(模拟)
- POJ 1350 Cabric Number Problem (6174问题)
- POJ 1350 Cabric Number Problem(水~)
- POJ 1350 Cabric Number Problem 笔记
- 1350 Cabric Number Problem
- POJ 1350 Cabric Number Problem (6174问题)水题
- poj1350 Cabric Number Problem
- Cabric Number Problem
- java类中获取tomcat路径
- RESTful API 设计指南
- 秋招历程
- HDU 5583 Kingdom of Black and White 暴力
- C指针在不同需求中的应用
- POJ 1350:Cabric Number Problem
- 字符串比较
- K-means(K均值原型聚类)
- Linux C语言编程环境之动态库和静态库
- 51nod 1482 部落信号[单调栈]
- java动态代理(JDK和cglib)
- eclise关闭自动更新
- .Net Dispose 记忆体释放
- linux mysql设置