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
  • 相关阅读:
    javamail发送邮件
    java复制文件夹中的所有文件和文件夹到另一个文件夹中
    jsp中使用out和response.getOutputStream的方法
    PHP数组用法
    PHP中的session
    java中list按照某个属性排序方法
    java读取xml文件内容
    C#实现验证码
    java实现验证码功能
    Java IO(四)------字节输入输出流
  • 原文地址:https://www.cnblogs.com/cyd308/p/4771390.html
Copyright © 2011-2022 走看看