• 个人简介

    我是王一川!!!!! 以下是我编的“小游戏”

    //2315 words
    //K-2M Wordle Game VickersPres (Vision Improved, ANLS-1 analysis mod)
    
    #include <bits/stdc++.h>
    #include <windows.h>
    #include <conio.h>
    
    using namespace std;
    
    const int NUMBER_OF_WORDS = 2315;
    
    string words[2316], answer, ty, rc[7];
    int cnt[26], rec[7][5];
    int sta[5]; //0 wrong, 1 right, 2 wrong location
    int ltsta[26]; //-1 unknown, 0 elimited, 1 included, 2 unknown location
    char kbd[4][20] = {{'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'}, 
    				   {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'},
    				   {'z', 'x', 'c', 'v', 'b', 'n', 'm'}};
    
    inline void Khavar (int FC, int BC) {
    	WORD wColor = ((BC & 0x0F) << 4) + (FC & 0x0F);
    	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
    }
    
    inline void Put_Record (int trn) {
    	for (int t = 0; t < trn; ++t) {
    		for (int i = 0; i < 5; ++i) {
    			if (rec[t][i] == 0) Khavar(12, 8);
    			if (rec[t][i] == 1) Khavar(12, 2);
    			if (rec[t][i] == 2) Khavar(12, 14);
    			cout << rc[t][i];
    		}
    		putchar('\n');
    	}
    	
    	Khavar(15, 0);
    }
    
    inline void Put_Keyboard_Status () {
    	for (int i = 0; i < 10; ++i) {
    		if (ltsta[kbd[0][i] - 'a'] == -1) Khavar(12, 0);
    		if (ltsta[kbd[0][i] - 'a'] == 0) Khavar(12, 8);
    		if (ltsta[kbd[0][i] - 'a'] == 1) Khavar(12, 2);
    		if (ltsta[kbd[0][i] - 'a'] == 2) Khavar(12, 14);
    		cout << (char)(kbd[0][i] - 32); Khavar(15, 0);
    		cout << ' ';
    	} putchar('\n');
    	
    	putchar(' ');
    	for (int i = 0; i < 9; ++i) {
    		if (ltsta[kbd[1][i] - 'a'] == -1) Khavar(12, 0);
    		if (ltsta[kbd[1][i] - 'a'] == 0) Khavar(12, 8);
    		if (ltsta[kbd[1][i] - 'a'] == 1) Khavar(12, 2);
    		if (ltsta[kbd[1][i] - 'a'] == 2) Khavar(12, 14);
    		cout << (char)(kbd[1][i] - 32); Khavar(15, 0);
    		cout << ' ';
    	} putchar('\n');
    	
    	putchar(' '); putchar(' ');
    	for (int i = 0; i < 7; ++i) {
    		if (ltsta[kbd[2][i] - 'a'] == -1) Khavar(12, 0);
    		if (ltsta[kbd[2][i] - 'a'] == 0) Khavar(12, 8);
    		if (ltsta[kbd[2][i] - 'a'] == 1) Khavar(12, 2);
    		if (ltsta[kbd[2][i] - 'a'] == 2) Khavar(12, 14);
    		cout << (char)(kbd[2][i] - 32); Khavar(15, 0);
    		cout << ' ';
    	} putchar('\n');
    }
    
    inline void ANLS_1 (int trn) {
    	system("cls");
    	Put_Record(trn); putchar('\n');
    	Put_Keyboard_Status(); Khavar(15, 0);
    	
    	int cnt = 0, ctt = 0; string sss[6];
    	
    	for (int t = 1; t <= NUMBER_OF_WORDS; ++t) {
    		bool flag = 1;
    		for (int i = 0; i < 5; ++i) 
    			if (ltsta[words[t][i] - 'a'] == 0) {
    				flag = 0; break;
    			}
    		
    		if (!flag) continue;
    		for (int i = 0; i < trn; ++i) {
    			for (int j = 0; j < 5; ++j) {
    				if (rec[i][j] == 1 && words[t][j] != rc[i][j]) {
    					flag = 0; break;
    				}
    				if (rec[i][j] == 2) {
    					if (words[t][j] == rc[i][j]) {
    						flag = 0; break;
    					}
    					bool ff = 1;
    					for (int k = 0; k < 5; ++k)
    						if (rc[i][j] == words[t][k]) {
    							ff = 0; break;
    						}
    					if (ff) {
    						flag = 0; break;
    					}
    				}
    			}
    			if (!flag) break;
    		}
    		
    		if (flag) {
    			cnt ++;
    			if (ctt < 5) 
    				sss[++ctt] = words[t];
    		}
    	}
    	
    	if (ctt > 1) printf("%d words are founded.\n", cnt);
    	else printf("%d word is founded.\n", cnt);
    	
    	printf("some possible words:\n");
    	Sleep(1000);
    	for (int i = 1; i <= ctt; ++i)
    		cout << sss[i] << '\n';
    	Sleep (1000);
    	printf("Press any key to continue.\n");
    	getch();
    	system("cls");
    	
    	Put_Record(trn);
    	putchar('\n');
    	Put_Keyboard_Status();
    	
    	Khavar(15, 0);
    	cout << "Please enter a 5-letter word.\n";
    	cout << "You have tried for " << trn;
    	if (trn > 1) cout << " turns.\n";
    	else cout << " turn.\n";
    	Sleep(500);
    	if (trn <= 2) 
    		Khavar(2, 0);
    	else if (trn <= 3) 
    		Khavar(14, 0);	
    	else if (trn <= 5)
    		Khavar(12, 0);
    	
    	if (5 - trn > 1)
    		printf("%d turns left.\n", 5 - trn);
    	else
    		printf("%d turn left.\n", 5 - trn);
    	Khavar(15, 0);
    	
    	printf("Enter \"helpY\" to run analysis.\n");
    }
    
    signed main () {
    	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    	SMALL_RECT windowSize = {0, 0, 30, 17};
    	SetConsoleWindowInfo(hConsole, TRUE, &windowSize);
    	
    	memset(ltsta, -1, sizeof ltsta);
    	Khavar(14, 0);
    	cout << "Loading words...\n";
    	
    	Sleep(1000);
    	
    	ifstream infile("WDsm1.txt");
    	ofstream outfile("status.save");
    	for (int i = 1; i <= NUMBER_OF_WORDS; ++i)
    		infile >> words[i];
    	
    	Khavar(2, 0);
    	cout << "OK.\n";
    	Sleep(1000);
    	
    	srand(time(NULL));
    	
    	int xr = rand() % NUMBER_OF_WORDS + 1;
    	answer = words[xr];
    	
    	Khavar(15, 0);
    	cout << "Press any key to continue.";
    	
    	getch();
    	
    	system("cls");
    	
    	int trn = 0;
    	
    	while (trn <= 5) {
    		Put_Record(trn);
    		putchar('\n');
    		Put_Keyboard_Status();
    		
    		Khavar(15, 0);
    		cout << "Please enter a 5-letter word.\n";
    		cout << "You have tried for " << trn;
    		if (trn > 1) cout << " turns.\n";
    		else cout << " turn.\n";
    		Sleep(500);
    		if (trn <= 2) 
    			Khavar(2, 0);
    		else if (trn <= 3) 
    			Khavar(14, 0);	
    		else if (trn <= 5)
    			Khavar(12, 0);
    		
    		if (5 - trn > 1)
    			printf("%d turns left.\n", 5 - trn);
    		else
    			printf("%d turn left.\n", 5 - trn);
    		Khavar(15, 0);
    		
    		printf("Enter \"helpY\" to run analysis.\n");
    		
    		cin >> ty; bool valid = 0;
    		if (ty == "helpY") {
    			ANLS_1(trn); cin >> ty;
    		}
    		
    		while (!valid) {
    			for (int i = 1; i <= NUMBER_OF_WORDS; ++i) 
    				if (words[i] == ty) {
    					valid = 1;
    					break;
    				}
    			
    			if (valid) break;
    			printf("Not in word list.\n");
    			Sleep(500);
    			printf("Please try again.\n");
    			Sleep(1000); system("cls");
    			
    			Put_Record(trn);
    			putchar('\n');
    			Put_Keyboard_Status();
    		
    			Khavar(15, 0);
    			cout << "Please enter a 5-letter word.\n";
    			cout << "You have tried for " << trn << " turns\n";
    			Sleep(500);
    			if (trn <= 2) 
    				Khavar(2, 0);
    			else if (trn <= 3) 
    				Khavar(14, 0);	
    			else if (trn <= 5)
    				Khavar(12, 0);
    			
    			printf("%d turns left.\n", 5 - trn);
    			Khavar(15, 0);
    			
    			printf("Enter \"helpY\" to run analysis.\n");
    			
    			cin >> ty;
    			
    			if (ty == "helpY") {
    				ANLS_1(trn); cin >> ty;
    			}
    		}
    		
    		rc[trn] = ty;
    		for (int i = 0; i < 26; ++i) cnt[i] = 0;
    		for (int i = 0; i < 5; ++i) {
    			cnt[answer[i] - 'a'] ++;
    		}
    		for (int i = 0; i < 5; ++i) {
    			if (ty[i] == answer[i]) {
    				sta[i] = 1, cnt[ty[i] - 'a'] --;
    				ltsta[ty[i] - 'a'] = 1;
    			} else {
    				if (cnt[ty[i] - 'a'] == 0) {
    					sta[i] = 0;
    					if (ltsta[ty[i] - 'a'] == -1)
    						ltsta[ty[i] - 'a'] = 0;
    				} else {
    					sta[i] = 2, cnt[ty[i] - 'a'] --;
    					if (ltsta[ty[i] - 'a'] == -1)
    						ltsta[ty[i] - 'a'] = 2;
    				}
    			}
    			
    			rec[trn][i] = sta[i];
    		}
    		
    		for (int i = 0; i < 5; ++i) {
    			if (sta[i] == 0) Khavar(12, 8);
    			if (sta[i] == 1) Khavar(12, 2);
    			if (sta[i] == 2) Khavar(12, 14);
    			cout << ty[i];
    			Sleep(500);
    		}
    		
    		Khavar(15, 0);
    		putchar('\n');
    		
    		if (ty == answer) {
    			Sleep(1000);
    			Khavar(2, 0);
    			printf("You win!\nYou have used %d turns.\n", trn + 1);
    			
    			Sleep(1000);
    			Khavar(15, 0);
    			cout << "Press any key to continue.";
    			getch();
    			return 0;
    		}
    		
    		system("cls");
    		
    		trn ++;
    		
    		outfile << ty << ' ';
    		for (int i = 0; i < 5; ++i)
    			outfile << sta[i] << ' ';
    		outfile << '\n';
    	}
    	
    	Put_Record(trn);
    	Khavar(12, 0);
    	printf("Game Over.\n"); Sleep(1000); Khavar(15, 0);
    	printf("The answer is "); cout << answer << '\n';
    	printf("Press any key to continue.");
    	getch();
    	
    	return 0;
    }
    
  • 通过的题目

  • 最近活动

    This person is lazy and didn't join any contests or homework.
  • 最近编写的题解

  • Stat

  • Rating

题目标签

模拟
16
NOIp 普及组
10
字符串
8
枚举
5
暴力
5
数论
3
数学
3
2004
2
2005
2
1998
1
2002
1
2008
1
2011
1
2013
1
2014
1
2016
1
系统测试
1
O2优化
1
提交答案
1
NOIp 提高组
1