11

卡塔库栗  •  2个月前


#include<bits/stdc++.h>
using namespace std;

bool iy(int year) {
	return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}

bool itrs(int year, int month, int day) {
	if (month < 1 || month > 12) return false;
	vector<int> dn = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if (iy(year)) dn[1] = 29;
	return day >= 1 && day <= dn[month - 1];
}

char ck(const string& id) {
	vector<int> coefficients = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
	string cs = "10X98765432";
	int sum = 0;
	for (int i = 0; i < 17; ++i) {
		sum += (id[i] - '0') * coefficients[i];
	}
	int remainder = sum % 11;
	return cs[remainder];
}

string vi(const string& id) {
	int year = stoi(id.substr(6, 4));
	int month = stoi(id.substr(10, 2));
	int day = stoi(id.substr(12, 2));

	if (year < 1980 || year >= 2007) return "Y";

	if (month < 1 || month > 12) return "M";

	if (!itrs(year, month, day)) return "D";

	char cd = ck(id);
	if (id[17] != cd) {
		string ci = id;
		ci[17] = cd;
		return ci;
	}

	return "T";
}

int main() {
	int n;
	cin >> n;
	cin.ignore();

	for (int i = 0; i < n; ++i) {
		string id;
		getline(cin, id);
		cout << vi(id) << endl;
	}

	return 0;
}

评论:

请先登录,才能进行评论