AC

⛆李恒旭₰₡₪∑¼☢Ⱉฅ☺☣☯☠  •  1年前


include <bits/stdc++.h>

using namespace std;

int main() {

int id_num;
cin >> id_num;
string ids[id_num];
string id;
for (int i = 0; i < id_num; i++) {
	cin >> ids[i];
}
for (int i = 0; i < id_num; i++) {
	id = ids[i];
	int y;
	int m;
	int d;
	int day_p[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int day_r[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int num[] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
	string num1 = "10X98765432";
	int max_day;
	int result = 0;
	string result1;
	if (id.substr(6, 4) < "1980" || id.substr(6, 4) > "2007") {
		cout << "Y" << endl;
		continue;
	} else {
		if (id.substr(10, 2) < "01" || id.substr(10, 2) > "12") {
			cout << "M" << endl;
			continue;
		} else {
			if (id.substr(12, 2) < "01" || id.substr(12, 2) > "31") {
				cout << "D" << endl;
				continue;
			} else {
				y = stof(id.substr(6, 4));
				m = stoi(id.substr(10, 2));
				d = stoi(id.substr(12, 2));

// printf("y:%d m:%d d:%d\n", y, m, d);

				if (y % 4 != 0 && y % 400 != 0) {
					max_day = day_p[m - 1];
					if (d > max_day) {
						cout << "D" << endl;
						continue;
					} else {
						for (int i = 0; i < id.length() - 1; i++) {
							result = (id[i] - '0') * num[i] + result;
						}
						result = result % 11;
						//cout << "result:" << result << endl;
						result1 = num1[result];

						if (result1.compare(id.substr(17, 1)) == 0) {
							cout << "T" << endl;
						} else {
							id.insert(17, result1);
							id.erase(18, 1);
							cout << id << endl;
						}
					}
				} else if (y % 4 == 0 || y % 400 == 0) {
					max_day = day_r[m - 1];
					if (d > max_day) {
						cout << "D" << endl;
						continue;
					} else {
						for (int i = 0; i < id.length() - 1; i++) {
							result = (id[i] - '0') * num[i] + result;
						}
						result = result % 11;

// cout<<"result:"<<result<<endl; result1 = num1[result];

						if (result1.compare(id.substr(17, 1)) == 0) {
							cout << "T" << endl;
						} else {
							id.insert(17, result1);
							id.erase(18, 1);
							cout << id << endl;
						}
					}
				}
			}
		}
	}

}
return 0;

}


评论:

请先登录,才能进行评论