• 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;
    }
  • 相关阅读:
    【必备】史上最全的浏览器 CSS & JS Hack 手册(转)
    iScroll4.2.5中的无法滑动或点击的解决方案(转)
    无障碍网页设计(WCAG2.0)
    大小端
    TCP报文结构
    A*
    shell中uniq与sort -u 两种去重的对别
    login流程
    类模板成员函数
    game 角色相关记录
  • 原文地址:https://www.cnblogs.com/chenjianxiang/p/3551917.html
走看看 - 开发者的网上家园