4003. I-number

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

#include<iostream>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
char s[100010],s1[100001];
int f(char s[])
{
	int l=strlen(s),sum=0;
	for(int i=0;i<l;i++)
		sum=sum+(s[i]-'0');
	return sum%10==0;
}
void add(char s[])
{
	int l=strlen(s),i;
	i=l-1;
	s[i]++;
	while(s[i]>'9')
	{
		s[i]='0';
		s[i-1]=s[i-1]+1;
		i--;
	}
}
int main()
{
	int t,x,l;
	cin>>t;
	while(t--)
	{
		s[0]='0';
		scanf("%s",s+1);
		add(s);
		while(!f(s))
			add(s);
		if(s[0]=='0')
		printf("%s\n",s+1);
		else
		printf("%s\n",s);
	}
	return 0;
}

好的,下面是一个基于你的要求的 C 语言代码,可以实现输入四个数字并循环显示: ```c #include <reg51.h> #define uchar unsigned char #define uint unsigned int sbit LSA=P2^2; sbit LSB=P2^3; sbit LSC=P2^4; uchar code table[]={ 0x3f, //0 0x06, //1 0x5b, //2 0x4f, //3 0x66, //4 0x6d, //5 0x7d, //6 0x07, //7 0x7f, //8 0x6f //9 }; uchar code keymap[]={ 1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, 14, 0, 15, 13 }; void delay(uint x) { uint i,j; for(i=x;i>0;i--) for(j=110;j>0;j--); } uchar read_key() { uchar i, j; uchar key = 0xff; for(i=0; i<4; i++) { P1 = ~(1<<i); j = P1 & 0xF0; if(j != 0xF0) { key = i*4 + ((j>>4) & 0x0F); while((P1 & 0xF0) != 0xF0); break; } } return key; } uchar get_digit(uchar num, uchar pos) { uchar digit; switch(pos) { case 0: digit = num / 1000; break; case 1: digit = (num % 1000) / 100; break; case 2: digit = (num % 100) / 10; break; case 3: digit = num % 10; break; default: digit = 0; break; } return digit; } void display(uchar num) { uchar i; for(i=0; i<4; i++) { LSA = i == 0 ? 1 : 0; LSB = i == 1 ? 1 : 0; LSC = i == 2 ? 1 : 0; P0 = table[get_digit(num, i)]; delay(1000); } } int main() { uchar i=0; uchar num[4] = {0, 0, 0, 0}; while(1) { uchar key = read_key(); if(key <= 9) { num[i] = key; i = (i + 1) % 4; } uchar j; for(j=0; j<4; j++) { int number = num[j]*1000 + num[(j+1)%4]*100 + num[(j+2)%4]*10 + num[(j+3)%4]; display(number); delay(500); display(number/10); delay(500); display(number/100); delay(500); display(number/1000); delay(500); } } return 0; } ``` 在这个代码中,我们在 `main` 函数中,对于输入的四个数字,先将它们依次组合成一个四位数字,并按照题目要求,在数码管上循环显示该数字的各个位数组合而成的数字。我们在 `display` 函数中,使用了 `get_digit` 函数来取得一个四位数字中某一位上的数字。同时,我们在各个数字之间加入了一定的延迟,以便于人眼观察区分。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值