6.E - Div. 7

You are given an integer n�. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by 77.

If there are multiple ways to do it, print any of them. If the given number is already divisible by 77, leave it unchanged.

Input

The first line contains one integer t� (1≤t≤9901≤�≤990) — the number of test cases.

Then the test cases follow, each test case consists of one line containing one integer n� (10≤n≤99910≤�≤999).

Output

For each test case, print one integer without any leading zeroes — the result of your changes (i. e. the integer that is divisible by 77 and can be obtained by changing the minimum possible number of digits in n�).

If there are multiple ways to apply changes, print any resulting number. If the given number is already divisible by 77, just print it.

#include <iostream>
#define endl '\n'
using namespace std;
int qi[1007];
int main()
{
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int cnt1=0;
	for(int i=14;i<999;i++)
	{
		if(i%7==0) qi[++cnt1]={i};
	}
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ans=0;
		int min=INT_MAX;
		for(int i=1;i<=cnt1;i++)
		{
			int t=qi[i],x=n,cnt2=0;
			if(t>=100&&x<100) continue;
			if(t<100&&x>=100) continue;
			while(t)
			{
				if(t%10!=x%10) cnt2++;
				t/=10;
				x/=10;
			}
			if(min>cnt2)
			{
				min=cnt2;
				ans=qi[i];
			}
		}
		cout<<ans<<endl;
	}
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值