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

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\n", tt++);
        else printf("Case #%d: No\n", tt++);
    }

    return 0;

}

  



 

转载于:https://www.cnblogs.com/Przz/p/5409786.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109370.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号