BNUZ-18-IT Festival K title Sao year, do you want to see the real AK

Sao Nian, you know the power of "AK".
The so-called AK means all kill, that is, to solve all the problems before the end of the game, and in the vast ACM arena, there are always teams looking for a way to AK, but this is often impossible. And twenty binary is the second base that just can express AK. This base will lead you to AK.
On the way to AK, it gives a twenty binary number a, hope you can find the smallest twenty binary number b greater than or equal to a, which can and is divisible by 7, because 7 is a lucky number, it will bring you good luck.
You can only see the real AK when you find the twenty-two binary number b. Come on, Sao Nian!
 
Note that in twenty binary:
A can be converted to decimal 10
B can be converted to decimal 11
...
K can be converted to decimal 20
L can be converted to decimal 21

input request

Each time, enter an integer T (1 <= T <= 100), and then enter T groups of test data and
then enter a twenty binary number a (0 <= a <= 22^100000) for each group of data
to ensure this Texagonal numbers only have uppercase letters [AL] and numbers [0-9]
 

output requirements

The output format of the first line of each set of data is "Case #i:", indicating that the
second line of the i-th test data output is the 20 binary number required by the question (all letters are represented in uppercase)
 

Test Data

input example

2
AC
AK
 

output example

Case #1:
AI
Case #2:
B3
 

Tips

For the first set of examples, the decimal number of AC is 232, and the next decimal number that is divisible by 7 is 238, which represents the twenty-two binary number AI


Solution : If the number in the n-ary system is converted into a decimal system, if it is 1, whether the n-ary system can divide the number is equal to the result of adding the number in each digit of the n-ary system into the decimal number. divide this number. Then there is the addition of large numbers . The senior who asked the question: I learned in elementary school mathematics that 21 can be divisible by 3, which is equivalent to 2+1=3. Whether it can be divisible by 3, but our team really didn't think about it. ps: Don't use map, I know tle, I don't dare to operate orz with snake skin anymore

AC code :

#include <iostream>
#include <map>
#include <string>
#include <cstdio>

using namespace std;

char nm[] = "0123456789ABCDEFGHIJKL";

int change(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return c - 'A' + 10;
}

int yuu(string a) { // ÇóÓà
	int sum = 0;
	for (int i = 0; a[i] != '\0'; i++) {
		sum += change(a[i]);
	}
	return sum % 7;
}

void _plus(string a, int yu) {
	int t[a.size()];
	for (int i = a.size()-1; i >= 0; i--) {
		t[i] = change(a[i]);
	}
	t[a.size()-1] += yu;
	for (int i = a.size()-1; i >= 0; i--) {
		if (t[i] >= 22) {
			a[i] = nm[t[i] % 22];
			if (i != 0)
				t[i-1]++;
			else
				a = "1" + a;
		} else {
			a[i] = nm[t[i]];
		}
	}
}

int main() {
	int t;
	string a;
	cin >> t;
	int case = 0;
	while (t--) {
		case++;
		cin >> a;
		int yu = yuu (a);
		string ans;
		if (yu == 0) {
			years = a;
		} else
			years = _plus(a, 7-yu);
		printf("Case #%d:\n", cas);
		cout << ans << endl;
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324519721&siteId=291194637