求思路 //不完整代码

许熠谦  •  1年前


include<stdio.h>

int main(){

int n,t;
char a[19][21];
scanf("%d",&n);
for(i=0;i<18;i++){
    for(j=0;j<n;j++){
        scanf("%c",&a[i][j]);
    }
}
 for(i=0;i<18;i++){
    for(j=0;j<n;j++){
       t= 
    }
 }

return 0; }


评论:

新鲜的题解,思路特别清晰

#include <stdio.h>

char s[25];
int year, month, date;
int coe[] = {0,7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
char match[] = {1,0,'X'-'0',9,8,7,6,5,4,3,2}; //为了简洁都减去'0'
int mon[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

void init()
{
	year = month = date = 0; //一定要初始化成0!!!
	for (int i = 7; i <= 10; i++)
	{
		year = year*10 + s[i]-'0'; //直接相加会很丑陋,所以写个循环
	}
	if (year % 4 == 0)
	{
		mon[2] = 29; //年份范围已经确定,直接判断是不是闰年即可
	}
	month = (s[11]-'0')*10 + s[12]-'0'; //直接获取月份
	date  = (s[13]-'0')*10 + s[14]-'0'; //直接获取日期
}


char decode()
{
	int sum = 0;
	for (int i = 1; i <= 17; i++)
	{
		sum += (s[i]-'0')*coe[i];
	}
	return match[sum%11]+'0';
}

void judge()
{
	if (year<1980 || year>2006)
	{
		printf("Y\n");
	}
	else if (month<1 || month>12)
	{
		printf("M\n");
	}
	else if (date<1 || date>mon[month])
	{
		printf("D\n");
	}
	else if (s[18] != decode())
	{
		s[18] = decode();
		printf("%s\n", s+1);
	}
	else
	{
		printf("T\n");
	}
}

int main() 
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		scanf("%s", s+1); //方便读取下标
		init();
		judge();
		mon[2] = 28; //初始化成原始日期
	}
	return 0;
}

CC  •  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;

}


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

请先登录,才能进行评论