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;
}