zoukankan      html  css  js  c++  java
  • poj1350

    简单题

    View Code
    #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()
    {
    //freopen("t.txt", "r", stdin);
    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=%d\n", 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 times\n", t);
    }
    return 0;
    }

  • 相关阅读:
    Delphi源程序格式书写规范
    ORACLE常用傻瓜问题1000问
    世界上最健康的作息时间表
    poj1657
    poj1604
    poj1654
    poj1635
    poj1655
    成为一个不折不扣的时间管理专家[推荐]
    男人的十三怕
  • 原文地址:https://www.cnblogs.com/rainydays/p/2087583.html
Copyright © 2011-2022 走看看