跳到正文

科技·工程

对拍

bsdsdb约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年1月24日
篇幅
约 2 分钟
获赞
2

版本

  1. v1当前

Windows

  • 1.cpp
  • bruteforce.cpp
  • gen_data.cpp
  • duipai.cpp:
C++
#include <bits/stdc++.h>
using namespace std;

int main() {
	int i = 0;
	do {
		system("gen_data.exe > in.txt");
		system("1.exe < in.txt > out.txt");
		system("bruteforce.exe < in.txt > ans.txt");
		cout << ++i << endl;
	} while (!system("fc out.txt ans.txt"));
	return 0;
}

MacOS / Linux

  • 1.cpp
  • bruteforce.cpp
  • gen_data.cpp
  • duipai.sh:
Bash
if ! [ -e $1.cpp ]; then
    echo "file doesn't exist"
    exit
fi
shopt -s expand_aliases
alias comp_cpp="g++ -O3 -Wall -Wextra -Wshadow -std=c++14"
comp_cpp bruteforce.cpp -o bruteforce.out
comp_cpp $1.cpp -o $1.out
comp_cpp gen_data.cpp -o gen_data
i=0
while true
do
    ./gen_data > in
    ./bruteforce.out < in > ans
    ./$1.out < in > out
    diff -b -B ans out > dif
    if [  -s ./dif ]; then
        echo $i
        echo "hack:"
		cat in
        echo "ans:"
        cat ans
        echo "out:"
        cat out
        rm -f $1.out bruteforce.out gen_data dif
		exit
	else
        let i++
        echo $i
    fi
done

用法:sudo chmod a+x duipaish; ./duipai.sh 1

原文