poj 1350 Cabric Number Problem

poj 1350 Cabric Number Problem,第1张

poj 1350 Cabric Number Problem
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;char st[100];bool check(){    for (int i = 1; i < 4; i++)        if (st[i] != st[i - 1]) return true;    return false;}int main(){    while (scanf("%s", st) != EOF)    {        if (st[0] == '-') break;        printf("N=%s:n", st);        if (!check() || strlen(st) != 4)        { printf("No!!n"); continue;        }        int t = 0;        int len = 4;        while (1)        { sort(st, st + len); int x, y; x = y = 0; for (int i = len - 1; i >= 0; i--)     x = x * 10 + st[i] - '0'; for (int i = 0; i < len; i++)     y = y * 10 + st[i] - '0'; printf("%d-%d=%dn", x, y, x - y); t++; if (x - y == 6174 || x - y == 0)     break; x = x - y; len = 0; while (x > 0) {     st[len] = x % 10 + '0';     x /= 10;     len++; }        }        printf("Ok!! %d timesn", t);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4900691.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存