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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 某Java大佬在地表最强Java企业(阿里)面试总结

    面试题真的是博大精深,也通过这个面试题学到了很多东西,很多笔者也不是很懂,如有描述错误的地方还望大佬赐教HashMap和Hashtable的区别Hashtable继承自Dictionary类,而HashMap继承自AbstractMap类。但二者都实现了Map接口。Hashtable中的方法是Synchronize的,而HashMap中的方法在缺省情况下是非Synchronize的。HashMap把Hashtable的contains方法去掉了,改成containsValue和contains.

    2022年4月7日
    47
  • 面向Windows的Pytorch完整安装教程

    面向Windows的Pytorch完整安装教程目录1.概述2.安装2.1安装cuda2.2安装cudnn2.3安装Pytoch2.4验证1.概述PyTorch是一个开源的Python机器学习库,其前身是著名的机器学习库Torch。2017年1月,由Facebook人工智能研究院(FAIR)基于Torch推出了PyTorch,它是一个面向Python语言的深度学习框架,不仅能够实现强大的GPU…

    2022年6月24日
    20
  • Oracle数据库学习的小结-1

    Oracle数据库学习的小结-1Oracle数据库监听配置 一、监听器(LISTENER)  监听器是Oracle基于服务器端的一种网络服务,主要用于监听客户端向数据库服务器端提出的连接请求。既然是基于服务器端的服务,那么它也只存在于数据库服务器端,进行监听器的设置也是在数据库服务器端完成的。 二、本地服务名(Tnsname)  Oracle客户端与服务器端的连接是通过客户端发出连接请求,由服务器

    2022年9月25日
    4
  • 树莓派win11镜像_树莓派安装镜像

    树莓派win11镜像_树莓派安装镜像2017-09-0410:40:47下载Hassbian镜像文件,浏览https://github.com/home-assistant/pi-gen/releases/tag/v1.23,查看最

    2022年8月4日
    5
  • Java性能优化的48条+七个案例

    Java性能优化的48条+七个案例Java性能优化的48条+七个案例

    2022年4月22日
    51
  • idea2021.4.14版本永久激活码_通用破解码

    idea2021.4.14版本永久激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    49

发表回复

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

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