2015 多校联赛 ——HDU5373(模拟)

Problem Description
In this problem, we should solve an interesting game. At first, we have an integer n, then we begin to make some funny change. We sum up every digit of the n, then insert it to the tail of the number n, then let the new number be the interesting number n. repeat it for t times. When n=123 and t=3 then we can get 123->1236->123612->12361215.
Sample Input
35 2 35 1 -1 -1
 
Sample Output
Case #1: Yes Case #2: No


对生成的数%11,余数与下次多增的部分结合,不停求余

(官方:用long long 写不好的会超时,是int的四倍  - -)


#include <iostream>
#include <cstdio>

using namespace std;
typedef long long ll;

int f(int sum)
{
    int i = 0;
    while(sum>0)
    {
        sum /= 10;
        i++;
    }

    return i;
}

int p(int num)
{
    int i = f(num);
    int sum = 1;
    while(i--)
    {
        sum *= 10;
    }

    return sum;
}

int main()
{
    int n, t, tt=1;
    while(scanf("%d%d", &n, &t))
    {
        if(n==-1&&t==-1) break;

        int sum = 0;
        int div = 0;
        int temp;
        int temps;

        temp  = n;
        while(temp>0)
        {
            sum += (temp%10);
            temp /= 10;
        }

        for(int i=0; i<t; i++)
        {
            div = n % 11;

            n = div*p(sum) + sum;

            temp = sum;
            temps = 0;
            while(temp>0)
            {
                temps += (temp%10);
                temp /= 10;
            }
            sum += temps;

        }
        if(n%11==0) printf("Case #%d: Yes
", tt++);
        else printf("Case #%d: No
", tt++);
    }

    return 0;

}

  







原文地址:https://www.cnblogs.com/Przz/p/5409786.html