13年杭电多校赛1解题报告

本文介绍了一种解决I-number问题的算法实现。该问题要求处理长度达100000的数字字符串,并通过逐个字符处理的方式进行进位操作,直至数字之和能被10整除。代码使用C++编写,涉及字符串处理、动态数组更新等技术。

1003:I-number

这题就是注意一下是数字长度是100000.,而不是数字大小是100000.只要逐个字符处理即可,当单个字符大于等于10时,向前进位。

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
int max(int a,int b)
{
    if(a<b)
        return b;
    else
        return a;
}
char a[111111];
int b[111111];
int main()
{
    int t , i ,sum = 0 ;

    cin >> t ;
    while(t--)
    {
        memset(b,0,sizeof(b));
        sum = 0 ;
        cin >> a ;
        int l = strlen(a) ;
        for(i = 0 ; i < l ; i ++)
        {
            b[i]=a[l - i - 1] - '0' ;
            sum += b[i] ;
        }
        while(1)
        {
            b[0] ++ ;
            sum ++;
            int current = 0 ;
            while(b[current] >= 10)
            {
                b[current] -= 10 ;
                sum -= 10 ;
                current ++ ;
                b[current] ++ ;
                sum ++ ;
            }
            l=max(l,current+1);
            if(sum % 10 == 0)
            {
                for(i = l - 1 ; i >= 0 ; i--)
                {
                    cout << b[i];
                }
                cout << endl ;
                break;
            }
        }
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值