Hack
查看原帖
Hack
1118614
I_Love_DS楼主2024/9/16 09:17

根据勾股定理,我写了一份对拍,duipai.cpp 代码如下:

#include <cstdlib>
#include <iostream>

int main() {
	// 构建比较文件的命令
	system("gen.exe > 1.txt");
	system("biaozhun.exe < 1.txt > 2.txt");
	system("wodechengxu.exe < 1.txt > 3.txt");
	
	// 执行命令
	int result = system("fc 2.txt 3.txt");
	
	// 检查命令执行结果
	if (result == 0) {
		std::cout << "Files are the same." << std::endl;
	} else {
		std::cout << "Files are different." << std::endl;
	}
	
	return 0;
}

wodechengxu.cpp 代码如下:

#include <bits/stdc++.h>

using namespace std;

string a;
string m[13] = {"", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
int md[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int day, month, year;
int ans = 0;
string M, Y;

int _1, _2;

bool run1(int x) {return x % 4 == 0;}

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

void work() {
	for (int i = 1; i < year; i++) {
		if (i < 1582) ans += 365 + run1(i);
		else if (i == 1582) ans += 355;
		else ans += 365 + run2(i);
	}
	if (year < 1582) {
		for (int i = 1; i < month; i++) ans += md[i];
		ans += day;
		if (month > 2) ans += run1(year);
	} else if (year == 1582) {
		for (int i = 1; i < month; i++) ans += md[i];
		ans += day;
		if ((month == 10 && day >= 15) || month > 10) ans -= 10;
	} else {
		for (int i = 1; i < month; i++) ans += md[i];
		ans += day;
		if (month > 2) ans += run2(year);
	}
	printf("%d\n", ans - 1);
  //////////////////////////////////////////
	if (ans - 1 == 0) _1 = 0;
	else if (ans - 1 == 1) _2 = 1;
	else {
		_1 = _2, _2 = ans - 1;
		if (_2 - _1 != 1) {
			cout << a << endl;
			exit(0);
		}
	}
  ///////////////////////////////////////
  
  // 用于快速检查哪里有问题,但是没有,大家可以试一下
}

void pre() {
	if (isdigit(a[1])) {
		day = (a[0] - '0') * 10 + (a[1] - '0');
		M = a.substr(2, 3);
		Y = a.substr(5, 4);
	}
	else {
		day = a[0] - '0';
		M = a.substr(1, 3);
		Y = a.substr(4, 4);
	}
	for (int i = 1; i <= 12; i++) if (M == m[i]) month = i;
	for (int i = 0; i < Y.size(); i++) year = year * 10 + Y[i] - '0';	
}

int main() {
	for (int i = 0; i <= 3652060; i++) {
		year = month = day = 0;
		ans = 0;
		cin >> a;
		pre();
		work();			
	}
	return 0;
}

下面是 gen.cpp 代码:(应该没有错吧)

// 包括了所有可能的情况
#include <bits/stdc++.h>

#define ll long long

using namespace std;

int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string m[13] = {"", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};

bool run1(int x) {return x % 4 == 0;}

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

int main() {
	for (int i = 1; i <= 9999; i++) {
		for (int j = 1; j <= 12; j++) {
			for (int k = 1; k <= month[j]; k++) {
				if (i == 1582 && j == 10 && (k > 4 && k < 15)) continue;
				cout << k << m[j] << i << endl;
				if (i < 1582 && j == 2 && k == 28 && run1(i)) cout << k + 1 << m[j] << i << endl;
				if (i > 1582 && j == 2 && k == 28 && run2(i)) cout << k + 1 << m[j] << i << endl;
			}
		}
	}
	return 0;
}

标准可以放题解的代码。

加上这一段:

  //////////////////////////////////////////
	if (ans - 1 == 0) _1 = 0;
	else if (ans - 1 == 1) _2 = 1;
	else {
		_1 = _2, _2 = ans - 1;
		if (_2 - _1 != 1) {
			cout << a << endl;
			exit(0);
		}
	}
  ///////////////////////////////////////

用于方便检查哪里出了问题。

目前找到的 Hack:

input:

1NOV1582

output:

577754

常见错解:

577764

其他的 Hack 待查找。

2024/9/16 09:17
加载中...