zoukankan      html  css  js  c++  java
  • HDU 4608 I-number

    Problem Description
    The I-number of x is defined to be an integer y, which satisfied the the conditions below:
    1. y>x;
    2. the sum of each digit of y(under base 10) is the multiple of 10;
    3. among all integers that satisfy the two conditions above, y shouble be the minimum.
    Given x, you're required to calculate the I-number of x.
     
    Input
    An integer T(T≤100) will exist in the first line of input, indicating the number of test cases.
    The following T lines describe all the queries, each with a positive integer x. The length of x will not exceed 105.
    Output
    Output the I-number of x for each query.
     
    Sample Input
    1
    202
     
    Sample Output
    208
     
    Source

    题目挺水的,不过是高精度

    #include <stdio.h>
    #include <string.h>
    
    int maxLen;
    int a[110000];
    int y[110000];
    
    void plus(int s){
        int carry=0;
        int cnt=0;
        int k=maxLen-1;
        if(s==10){
            y[cnt++]=a[k--];
            carry=(a[k]+1)/10;
            y[cnt++]=(a[k]+1)%10;
            k--;
        }else{
            y[cnt++]=(a[k]+s)%10;
            carry=(a[k]+s)/10;
            k--;
        }
        while(carry!=0 || k>=0){
            if(k>=0){
                y[cnt++]=(a[k]+carry)%10;
                carry=(a[k]+carry)/10;
                k--;            
            }else{
                y[cnt++]=carry;
                carry=0;
            }
        }
        maxLen=cnt;
    }
    
    int main()
    {
        int T;
        char x[110000];
        scanf("%d",&T);
        while( T-- ){
            int sum=0;
            int cnt=0;
            scanf("%s",x);
            for(int i=0; x[i]!=''; i++){
                sum+=x[i]-'0';
                a[cnt++]=x[i]-'0';
            }
            maxLen=cnt;
            int t=10-sum%10;
            if(t>=(10-a[maxLen-1])){
                plus(10-a[maxLen-1]);
                sum=0;
                cnt=0;
                for(int i=maxLen-1; i>=0; i--){
                    sum+=y[i];
                    a[cnt++]=y[i];
                }
                t=10-sum%10;
                if(sum%10!=0)
                    plus(t);
            }else{
                plus(t);    
            }
            for(int i=maxLen-1; i>=0; i--){
                printf("%d",y[i]);
            }
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    wepack使用
    js 原型链
    react 生命周期
    settimeout--原来定时器是有三个及以上参数的
    我所未知的 typeof 现象
    js 里面的 function 与 Function
    ECMAScript 对象类型
    js阻碍DOM加载
    面试问题与心得
    Java IO 乱码
  • 原文地址:https://www.cnblogs.com/chenjianxiang/p/3551917.html
Copyright © 2011-2022 走看看