zoukankan      html  css  js  c++  java
  • Codeforces Round #643 (Div. 2) A. Sequence with Digits(暴力)

    Let's define the following recurrence:

    an+1=an+minDigit(an)maxDigit(an).an+1=an+minDigit(an)⋅maxDigit(an).

    Here minDigit(x)minDigit(x) and maxDigit(x)maxDigit(x) are the minimal and maximal digits in the decimal representation of xx without leading zeroes. For examples refer to notes.

    Your task is calculate aKaK for given a1a1 and KK .

    Input

    The first line contains one integer tt (1t10001≤t≤1000 ) — the number of independent test cases.

    Each test case consists of a single line containing two integers a1a1 and KK (1a110181≤a1≤1018 , 1K10161≤K≤1016 ) separated by a space.

    Output

    For each test case print one integer aKaK on a separate line.

    Example
    Input
    Copy
    8
    1 4
    487 1
    487 2
    487 3
    487 4
    487 5
    487 6
    487 7
    
    Output
    Copy
    42
    487
    519
    528
    544
    564
    588
    628
    按题目说的模拟,特别地,一个数里出现0的时候直接输出当前数并break。
    #include <bits/stdc++.h>
    using namespace std;
    long long a,k;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            cin>>a1>>k;
            int cnt;
            if(k==1)
            {
                cout<<a<<endl;
                continue;
            }
            for(cnt=2;cnt<=k;cnt++)
            {
                int mmax=-1,mmin=10;
                long long temp=a;
                while(temp)//拆分数字
                {
                    int dig=temp%10;
                    mmax=max(mmax,dig);
                    mmin=min(mmin,dig);
                    temp/=10;
                }
                if(k==cnt)
                {
                    cout<<a+mmax*mmin<<endl;
                }
                else if(mmin==0)//出现0了 累加之后还是0 因此直接输出 终止循环
                {
                    cout<<a+mmax*mmin<<endl;
                    break;
                }
                else a+=mmax*mmin;
            }
        }
    }


  • 相关阅读:
    Mybatis实现数据的增删改查(CRUD)
    Spring MVC基础入门
    Swap in C C++ C# Java
    java和c#使用hessian通信
    基于Netty4的HttpServer和HttpClient的简单实现
    RabbitMQ的几种典型使用场景
    java多线程编程
    singleton pattern的推荐实现
    python多线程编程
    基于GMap.Net的地图解决方案
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12902759.html
Copyright © 2011-2022 走看看