zoukankan      html  css  js  c++  java
  • 多校7 1005 The shortest problem

    The shortest problem

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


    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
     1 #include <stdio.h>
     2 
     3 int ss(int x)
     4 {
     5     int i,j,su=0;
     6     while(x)
     7     {
     8         su=su+x%10;
     9         x=x/10;
    10     }
    11     return su;
    12 }
    13 
    14 int sss(int x)
    15 {
    16     int cnt=0;
    17     while(x)
    18     {
    19         cnt++;
    20         x=x/10;
    21     }
    22     return cnt;
    23 }
    24 
    25 int dd(int x,int y)
    26 {
    27     int i;
    28     for(i=1;i<=y;i++)
    29         x=x*10;
    30     return x;
    31 }
    32 
    33 int main()
    34 {
    35     int n,t,s,mo;
    36     int i,j,k,ca=0;
    37     while(scanf("%d %d",&n,&t)!=EOF)
    38     {
    39         if(n==-1 && t==-1)
    40             break;
    41         s=ss(n),mo=n%11;
    42         //printf("$%d %d
    ",mo,s);
    43         for(i=1;i<=t;i++)
    44         {
    45             mo=(dd(mo,sss(s))+s)%11;
    46             s=s+ss(s);
    47             //printf("$%d %d
    ",mo,s);
    48         }
    49         printf("Case #%d: ",++ca);
    50         if(mo==0)
    51             printf("Yes
    ");
    52         else
    53             printf("No
    ");
    54     }
    55 }
    View Code
  • 相关阅读:
    BNU 沙漠之旅
    手把手教你在Windows端搭建Redmine项目管理软件
    [置顶] mybatis批量新增系列之有主键的表的批量新增
    linux 命令之sar——监视系统状态
    简单的串行通信程序
    Hibernate_12_HQL句子
    初次使用glog
    2014辛星在读CSS第八节 使用背景图片
    poj 2763 Housewife Wind(树链拆分)
    堆,队列,单一列表,双向链表
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771390.html
Copyright © 2011-2022 走看看