zoukankan      html  css  js  c++  java
  • 2015 Multi-University Training Contest 7 1005

    The shortest problem

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 380    Accepted Submission(s): 186


    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.
     
    Input
    Multiple input.
    We have two integer n (0<=n<=104 ) , t(0<=t<=105) in each row.
    When n==-1 and t==-1 mean the end of input.
     
    Output
    For each input , if the final number are divisible by 11, output “Yes”, else output ”No”. without quote.
     
    Sample Input
    35 2
    35 1
    -1 -1
     
    Sample Output
    Case #1: Yes
    Case #2: No
     
    Source
     
    题意:将前面的每位数相加得到的数加到最后,如此往复执行n次,问最后得到的数字能否被11整除
    分析:模拟一次就行,注意答案可能计算中的结果可能会超int
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<string>
    #include<iostream>
    #include<cstring>
    #include<cmath>
    #include<stack>
    #include<queue>
    #include<vector>
    #include<map>
    #include<stdlib.h>
    #include<algorithm>
    #define LL __int64
    using namespace std;
    LL num,n,ans,sum;
    
    LL calc(LL x)
    {
        LL res=0;
        while(x)
        {
            res+=x%10;
            x=x/10;
        }
        return res;
    }
    
    LL count_digit(LL x)
    {
        if(x==0) return 10;
        LL ok=1;
        while(x)
        {
            x=x/10;
            ok=ok*10;
        }
        return ok;
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        int Case=0;
        while(scanf("%I64d %I64d",&num,&n)!=EOF)
        {
            if(num==-1 && n==-1) break;
    
            ans=calc(num);//ans表示当前要加在后排的数
            sum=num;//sum表示累加的和
            for(int i=1;i<=n;i++)
            {
                sum=sum*count_digit(ans)+ans;
                sum=sum%11;
                ans=ans+calc(ans);
            }
    
            printf("Case #%d: ",++Case);
            if(sum%11==0) printf("Yes
    ");
            else printf("No
    ");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    文本PDG文件名构成
    关于文本PDG的字体
    Oracle 11G R2 在windows server 2008 64位安装时提示:无法在windows "开始"菜单或桌面上创建项
    GTONE上安装插件无法显示SecurityPrism菜单
    Centos系统下Lamp环境的快速搭建(超详细)
    Windows 10激活
    word如何让单页变横向
    redhat 6.x 上创建用户
    redhat下网络的配置
    Windows 10、Windows 2012 安装 Oracle 11g 报错:[INS-13001]环境不满足最低要求。
  • 原文地址:https://www.cnblogs.com/clliff/p/4722296.html
Copyright © 2011-2022 走看看