• 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
  • 相关阅读:
    我决定潜心研究技术了...
    new proxy
    谷歌插件开发
    js计算不准确 解决方案
    netty中如何切包
    Spring Boot的ComponentScan原理
    解决org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token found character '@'
    深入理解js立即执行函数
    winform 将子窗体显示在父窗体的TabControl控件上
    js隐藏网页元素
  • 原文地址:https://www.cnblogs.com/clliff/p/4722296.html
Copyright © 2020-2023  润新知