hdu 4608 I-number 模拟

简介:

    标程用的是高精,但其实不需要,只要先判断个位能否满足,不能的话就向前找到第一个不是9的数加1即可,还不行就变成1xxx9的形式


/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char x[100005];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",x);
        int len=strlen(x),i,sum=0;
        for(i=0;i<len;i++)
            sum+=x[i]-'0';
        sum-=x[len-1]-'0';
        if(x[len-1]<':'-sum%10&&sum%10!=0) //':'=10+'0'
            x[len-1]=':'-sum%10;
        else
        {
            for(i=len-2;i>=0;i--)
            {
                if(x[i]!='9')
                {
                    x[i]++;
                    x[len-1]='9'-sum%10;
                    break;
                }
                sum-=9;
                x[i]='0';
            }
            if(i==-1)putchar('1'),x[len-1]='9';
        }
        printf("%s\n",x);
    }
}


目录
相关文章
|
人工智能 Java
HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem J. number sequence
HDU - 2018杭电ACM集训队单人排位赛 - 4 - Problem J. number sequence
139 0
HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
121 0
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
121 0
|
Java Windows
HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】
Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 175657    Accepted Submission...
873 0
|
Java
HDU 1711 Number Sequence(KMP裸题,板子题,有坑点)
Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 27028    Accepted Submission...
1028 0
|
人工智能
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let (1) x % a = 0;...
1066 0
|
机器学习/深度学习 人工智能