多校联合练习赛1 problem1009 I-number 信心题啊。。。

73 篇文章 21 订阅
56 篇文章 0 订阅

I-number

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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 10 5.
 

Output
  
  
Output the I-number of x for each query.
 

Sample Input
  
  
1 202
 

Sample Output
  
  
208
 

Source
  
  
2013 Multi-University Training Contest 1
 

貌似是最水的一道。高精度每次加1就过去了。。。题目意思就是找个比x大且能各个数位上的和能被10整除的数。。

/*
 * @author ipqhjjybj
 * @date  20130723
 *
 */

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

#include <iostream>
#include <cmath>
#include <algorithm>

#include <cstring>
#include <vector>
#include <string>
using namespace std;

#define inf 0x3f3f3f3f
#define MAXN 100005
#define clr(x,k) memset((x),(k),sizeof(x))
#define cpy(x,k) memcpy((x),(k),sizeof(x))
#define Base 10000

typedef vector<int> vi;
#define foreach(it,c) for(vi::iterator it = (c).begin();it != (c).end();++it)

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
char s[MAXN];
int num[MAXN];
int len;
void add(int a[],int num){
    a[0]+=num;
    for(int i=0;i<len;i++){
        if(a[i]>9){
            a[i+1]+=a[i]/10;
            a[i]%=10;
        }
    }
    while(a[len]){
        a[len+1]=a[len]/10;
        a[len]%=10;
        len++;
    }
  //  for(int i=len-1;i>=0;i--)
    //    printf("%d",a[i]);printf("\n");
}
int count(int a[]){
    int sum=0;
    for(int i = 0;i < len;i++)
        sum+=a[i];
    if(!(sum%10))
        return 1;
    else return 0;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",s);
        len = strlen(s);
        clr(num,0);
        for(int i = len-1,j=0;i>=0;i--,j++)
            num[i] = s[j]-'0';
        do{
            add(num,1);
        }while(!count(num));
        //print
        for(int i=len-1;i>=0;i--)
            printf("%d",num[i]);printf("\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值