zoukankan      html  css  js  c++  java
  • 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;
    
    }
    

      







  • 相关阅读:
    现在的女生真会装...
    C语言操作注册表 写入 读取信息
    C++ 简单字符串加解密(转载)
    C++ 操作XML文件 使用MSXML.DLL
    C++ vector容器find查询函数
    C++ 共享内存 函数封装
    获取屏幕像素点···
    MFC像窗体坐标位置发送 点击消息
    mfc对话询问窗体
    MFC去掉标题栏
  • 原文地址:https://www.cnblogs.com/Przz/p/5409786.html
Copyright © 2011-2022 走看看