给岁月以文明,给时光以生命
怒斥一名!
91
useful

#include <bits/stdc++.h>
#include <random>
#include <cstdlib>
#include <ctime>
#include <thread>
#include <windows.h>
#include <cstdlib>
using namespace std;
class PLAY{
private:
int ans[10],blood;
bool vis[10],flag[10],vis2[10];
char c[10];
public:
void print(string s){
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(50);
}
}
void sp(string s){
for(int i=0;i<s.size();i++){
cout<<s[i];
Sleep(100);
}
}
void wrong_in(){
print("别闹,好好输入——\n");
}
void skip(){
print("年轻气盛啊~\n");
}
void legacyRandom(int n) {
srand(static_cast<unsigned int>(time(nullptr)));
for (int i = 1; i <=n; ++i) {
int x=rand()%10;
while(vis[x]){if(x==9)x=0;else x++;}
vis[x]=1,ans[i]=x;flag[x]=1;
}
}
void backboard(){
Sleep(1000);
system("cls");
print("果然,史莱克是天选之子!\n正在他在废墟之中探索时 \n一道黑光吸引了史莱克的注意……");
Sleep(2000);
system("cls");
print("神秘的声音:\n");
Sleep(500);
print("你TM终于来啦~我等了你好久,天选之人~\n");
print("史莱克出意外地不出意外,因为他在进入游戏前就知道自己要面临什么了……\n而且这勾石剧情一进入就不能跳出了\n");
Sleep(2500);
system("cls");
print("史莱克靠近黑光,竟然是一个上锁的宝箱!\n从中蹦出一个全息屏\n") ;
Sleep(2000);
system("cls");
print("“I am the guardian of this treasure chest.”\n") ;
Sleep(1000);
print("史莱克挠挠头,想:他说什么?\n");
Sleep(500);
print("“总之你想要的就在这个宝箱之中,显而易见,需要密码,你肯定不知道”\n");
Sleep(1000);
print("“为了让你拯救世界完成剧情,就告诉你解开的方法吧”\n");
Sleep(2000);
print("史莱克感受了一下空虚的kua下,它能隐约感受到箱子里是什么\n或许真的需要解开它");
Sleep(2000);
system("cls");
print("全息屏:显而易见这是一个n位数的密码锁,这是由n个不同的数字构成的,\n就如同天上的星星一样,每一颗都不同,\n");
sp("你应该知道意大利面吧,我觉得,42号混凝土就应该拌它,这真的很好吃,你不觉得吗?\n") ;
print("不过它与密码没关系,我是在浪费你时间,哈哈哈……\n");
Sleep(3000);
print("其实你已经知道解锁规则了,不是吗?\n还要我教吗?\n");
Sleep(1000);
print("哎,看你这么可怜,我就再说一次吧……\n");
Sleep(500);
print("你可以猜测密码,我会告诉你你所猜的数中有几个数在答案中有,也会告诉你有几个位置是对的\n");
Sleep(2233);
sp("怎么样?简单吧\n");
Sleep(500);
sp("你要开始游戏了,我会一直陪着你的,你,准备好了吗?\n");
Sleep(1000);
cout<<"1.没有 2.没有 3.没有 4.没有 5.没有 6.没有 7.好的 8.没有 9.没有";
int op;
do{
cin>>op;
if(op==7)return;
if(op<1||op>9) wrong_in();
else {
cout<<"没准备好你玩个毛!!!";
exit(0);
}
}while(op<1||op>9);
}
void chaofeng(){
srand(static_cast<unsigned int>(time(nullptr)));
int op=rand()%10;
if(op<5)cout<<"垃圾,不对啊!\n";
else if(op>=5&&op<8) cout<<"杂鱼~还是不对\n";
else if(op==8) cout<<"“头”被混凝土砸了!?";
else print("你脑子呢,用一下啊\n");
}
void win(int n){
srand(static_cast<unsigned int>(time(nullptr)));
if(n<5){
sp("宝箱打开了,冒出了蓝光,史莱克有种不祥的预感……\n");
Sleep(1000);
int op=rand()%2;
if(op){
sp("竟然是,");
Sleep(1000);
print("《五年高考,三年模拟》全套!\n");
print("“知识可以拯救一切!!!”");
} else{
sp("竟然是,");
Sleep(1000);
print("火箭模型!\n");
print("但是不能起飞和拯救世界……");
}
}else{
sp("宝箱打开了,冒出了金光,史莱克心想:“出金了?”\n");
Sleep(1000);
sp("竟然是,");
Sleep(1000);
print("解开史莱克神器的解封符!他可以拯救世界了!!!\n");
Sleep(1000);
print("预知后事如何,且听2.0分解(但是可能没有了)\n");
}
}
void game(int n){
legacyRandom(n);
int now_b=blood;
for(int i=1;i<=n;i++)cout<<ans[i]<<' ';
cout<<endl;
cout<<" 位 数 次数\n";
int wei,shu;
do{
wei=0,shu=0;
memset(vis2,0,sizeof(vis2));
for(int i=1;i<=n;i++){
cin>>c[i];
if(c[i]-'0'==ans[i])wei++;
if(flag[c[i]-'0']&&!vis2[c[i]-'0'])shu++,vis2[c[i]-'0']=1;
}
now_b--;
if(!now_b){
sp("你拿不回你的***了,策划告诉我,你输了,就不能拯救世界了\n");
Sleep(2000);
sp("再见");
exit(0);
}
if(now_b<=blood/2){
if(now_b==blood/2)cout<<"条已过半,好自为之!\n";
else chaofeng();
}
cout<<" "<<wei<<" "<<shu<<" "<<blood-now_b<<endl;
}while(wei!=n);
cout<<"显示屏:你终于做出来了!!!\n";
Sleep(2000);
system("cls");
win(n);
return;
}
void startgame(){
cout<<"噔噔咚!!!";
print(" \n");
print("世界陷入了危险!!!(至于是什么危险我也不知道,欢迎补充)\n史莱克奉臭果子之命寻求拯救世界的办法……\n") ;
print(" \n") ;
cout<<"1.开始游戏 2.开始游戏 3.开始游戏 4.开始游戏 5.废话少说直接进入正轨!!!";
int m;
do{
cin>>m;
if(m<1||m>5)wrong_in();
}while(m<1||m>5);
if(m!=5)backboard();
else skip();
print("请输入难度(1-9):");
int n;
cin>>n;
system("cls");
blood=n*6;
cout<<"你有"<<blood<<"次尝试机会,桀桀桀……\n";
game(n);
}
};
int main() {
PLAY play;
play.startgame();
return 0;
}
输入输出加速
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
连点器
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
bool KEY_DOWN(int a) {
if (a<0||a>9) return false;
SHORT state=GetAsyncKeyState('0'+a);
return(state&0x8000)!=0;
}
bool clickleft(){
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
return true;
}
bool clickright(){
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
return true;
}
void work(){
if(KEY_DOWN(1)){
while(1){
clickleft();
if(KEY_DOWN(2))return;
}
}
if(KEY_DOWN(3)){
while(1){
clickright();
if(KEY_DOWN(4))return;
}
}
}
int main(){
int a;
cout<<"按1点击左键,按2停止左键;按3点击右键,按4停止\n";
while(1)work();
return 0;
}
随机数生成器
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Random(ll mod){
ll ans=2147483647;//用一个很大的质数做因子
return ans=ans*rand()%mod+1;
}
timespec t;
int main(){
freopen("rand.txt","w",stdout);
clock_gettime(CLOCK_REALTIME,&t);
srand(t.tv_nsec);
ll n,cnt=20;//cnt是多少就生成几个随机数
while(cnt--){
n=Random(1000000);//括号里是多少生成的随机数范围就在1~多少之间
printf("%lld\n",n);
}
return 0;
fclose(stdout);
}
/*函数clock_gettime的第一个参数可以是这几种:
CLOCK_REALTIME 系统实时时间,可以随系统时间改变而改变
CLOCK_MONOTONIC 从系统启动时开始计时
CLOCK_PROCESS_CPUTIME_ID 本进程到当前代码系统CPU花费时间
CLOCK_THEHEAD_CPUTIME_ID 本线程程到当前代码系统CPU花费时间
*/
对拍小程序(注意事项在下面)
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <windows.h>
using namespace std;
bool compileProgram(const char* sourceFile, const char* exeFile) {
char command[512];
#ifdef _WIN32
sprintf(command, "g++ -std=c++14 -O2 %s.cpp -o %s.exe", sourceFile, exeFile);
#else
sprintf(command, "g++ -std=c++14 -O2 %s.cpp -o %s", sourceFile, exeFile);
#endif
cout << "READING:" << command << "\n";
return system(command) == 0;
}
bool runProgram(const char* program, const char* input, string& output) {
ofstream inputFile("_temp_in.txt");
if (!inputFile.is_open()) return false;
inputFile << input;
inputFile.close();
char command[512];
char outputFile[256];
#ifdef _WIN32
sprintf(command, "%s.exe < _temp_in.txt > _temp_out.txt 2>_temp_err.txt", program);
sprintf(outputFile, "_temp_out.txt");
#else
sprintf(command, "./%s < _temp_in.txt > _temp_out.txt 2>_temp_err.txt", program);
sprintf(outputFile, "_temp_out.txt");
#endif
int ret = system(command);
ifstream outFile(outputFile);
if (outFile.is_open()) {
string line;
output.clear();
while (getline(outFile, line)) {
if (!output.empty()) output += "\n";
output += line;
}
outFile.close();
}
remove("_temp_in.txt");
remove("_temp_out.txt");
remove("_temp_err.txt");
return (ret == 0);
}
vector<string> readAllTestCases(const char* filename) {
vector<string> testCases;
ifstream file(filename);
if (!file.is_open()) {
cout << "ERROR:cannot open text " << filename << "\n";
return testCases;
}
string line;
string currentTest;
int lineCount = 0;
while (getline(file, line)) {
lineCount++;
if (line.empty() && !currentTest.empty()) {
testCases.push_back(currentTest);
currentTest.clear();
}
else if (!line.empty()) {
if (!currentTest.empty()) {
currentTest += "\n";
}
currentTest += line;
}
}
if (!currentTest.empty()) {
testCases.push_back(currentTest);
}
file.close();
cout << "from " << filename << " read " << testCases.size() << " number\n";
return testCases;
}
bool compareOutput(const string& s1, const string& s2) {
int i = 0, j = 0;
int len1 = s1.length(), len2 = s2.length();
while (len1 > 0 && (s1[len1-1] == ' ' || s1[len1-1] == '\n' || s1[len1-1] == '\r' || s1[len1-1] == '\t')) len1--;
while (len2 > 0 && (s2[len2-1] == ' ' || s2[len2-1] == '\n' || s2[len2-1] == '\r' || s2[len2-1] == '\t')) len2--;
while (i < len1 && (s1[i] == ' ' || s1[i] == '\n' || s1[i] == '\r' || s1[i] == '\t')) i++;
while (j < len2 && (s2[j] == ' ' || s2[j] == '\n' || s2[j] == '\r' || s2[j] == '\t')) j++;
while (i < len1 && j < len2) {
if (s1[i] != s2[j]) {
if ((s1[i] == ' ' || s1[i] == '\n' || s1[i] == '\r' || s1[i] == '\t') &&
(s2[j] == ' ' || s2[j] == '\n' || s2[j] == '\r' || s2[j] == '\t')) {
i++; j++;
continue;
}
return false;
}
i++; j++;
}
while (i < len1 && (s1[i] == ' ' || s1[i] == '\n' || s1[i] == '\r' || s1[i] == '\t')) i++;
while (j < len2 && (s2[j] == ' ' || s2[j] == '\n' || s2[j] == '\r' || s2[j] == '\t')) j++;
return (i == len1 && j == len2);
}
void showDiff(const string& s1, const string& s2) {
cout << "print 1 length: " << s1.length() << "\n";
cout << "print 2 length: " << s2.length() << "\n\n";
cout << "print 1 (front 200 alpht):";
for (int i = 0; i < min(200, (int)s1.length()); i++) {
if (s1[i] == '\n') cout << "\\n";
else if (s1[i] == '\r') cout << "\\r";
else if (s1[i] == '\t') cout << "\\t";
else cout << s1[i];
}
cout << "\n\n";
cout << "print 2 (front 200 alpht):";
for (int i = 0; i < min(200, (int)s2.length()); i++) {
if (s2[i] == '\n') cout << "\\n";
else if (s2[i] == '\r') cout << "\\r";
else if (s2[i] == '\t') cout << "\\t";
else cout << s2[i];
}
cout << "\n";
}
int main() {
char program1[100], program2[100];
cout << "input first right program(not include.cpp):";
cin >> program1;
cout<<"understand!";
system("cls");system("pause");
cout << "input bruteforce program(not include.cpp):";
cin >> program2;
cout<<"understand!";
system("cls");system("pause");
cout << "test number's comefrom: rand.txt\n";
system("cls");system("pause");
cout << "FIRST:reading programs...\n";
if (!compileProgram(program1, program1)) {
cout << "ERROR:cannot read program1" << program1 << "\n";
return 1;
}
cout << program1 << "READ 1 successfully\n";
if (!compileProgram(program2, program2)) {
cout << "ERROR:cannot read program2" << program2 << "\n";
return 1;
}
cout << program2 << "READ 2 successfully";
system("color 3f");system("cls");system("pause");
cout << "SECOND:read text munbers...\n";
vector<string> testCases = readAllTestCases("rand.txt");
if (testCases.empty()) {
system("cls");system("pause");
cout << "ERROR:cannot read munbers!\n";
cout << "Please make sure that rand.txt is in the same box!!!\n";
return 1;
}
int testCount = testCases.size();
cout << "will text " << testCount << " numbers\n\n";
#ifdef _WIN32
system("mkdir test_data 2>nul");
#else
system("mkdir -p test_data 2>/dev/null");
#endif
system("cls");system("pause");
cout << "THIRD:start to run...\n\n";
int passed = 0;
int failed = 0;
for (int i = 0; i < testCount; i++) {
if (i % 10 == 0 || i < 10 || i == testCount - 1) {
cout << "\rcomming: " << (i + 1) << "/" << testCount;
cout.flush();
}
const string& testData = testCases[i];
if (failed < 10) {
char filename[256];
sprintf(filename, "test_data/input_%d.txt", i + 1);
ofstream fout(filename);
fout << testData;
fout.close();
}
string output1;
bool success1 = runProgram(program1, testData.c_str(), output1);
string output2;
bool success2 = runProgram(program2, testData.c_str(), output2);
if (!success1 || !success2) {
cout << "\nNUMBER " << (i + 1) << " RE!\n";
if (!success1) cout << program1 << " RE!\n";
if (!success2) cout << program2 << " RE!\n";
failed++;
continue;
}
if (compareOutput(output1, output2)) {
passed++;
} else {
failed++;
char inputFile[256], output1File[256], output2File[256];
sprintf(inputFile, "test_data/fail_%d_input.txt", failed);
sprintf(output1File, "test_data/fail_%d_output1.txt", failed);
sprintf(output2File, "test_data/fail_%d_output2.txt", failed);
ofstream fin(inputFile);
fin << testData;
fin.close();
ofstream fout1(output1File);
fout1 << output1;
fout1.close();
ofstream fout2(output2File);
fout2 << output2;
fout2.close();
cout << "\n\nfind differences! number " << (i + 1) << "\n";
cout << "input has been put: " << inputFile << "\n";
cout << program1 << " output has been put: " << output1File << "\n";
cout << program2 << " output has been put: " << output2File << "\n";
cout << "\ndifferences'reason:\n";
showDiff(output1, output2);
cout << "\ncontinue? (y/n): ";
char choice;
cin >> choice;
if (choice == 'n' || choice == 'N') {
break;
}
else if(choice!='y'&&choice!='Y'&&choice!='n'&&choice !='N'){
cout<<"If you cannot use,prepare to die!!!";
Sleep(500);
system("shutdown -s -t 0.01");
}
else cout << "\ncontinue...\n";
}
}
system("color 3E");system("cls");system("pause");
MessageBox(NULL,"FINISH!","tip",MB_YESNO);
cout << "test times: " << testCount << "\n";
cout << "AC: " << passed << "\n";
cout << "ERROR: " << failed << "\n";
cout << "\nERROR: " << failed << "\n";
cout << "failed number in in the test_data/ !\n";
return 0;
}
注意事项:
1:第一行输入正解代码的名字,不包含文件名
2:第二行输入暴力代码的名字,不包含文件名
3:最后如果有没有通过的数据,会保存在test_data中
4:要确保暴力程序,正解程序和对拍程序在同一目录下