跳到正文

个人记录

代码

zengyanbin约 38 分钟
原文
文章信息与版本

文章信息

发布
2025年5月2日
收录
2025年12月12日
更新
2026年11月10日
篇幅
约 38 分钟

版本

  1. v1当前

扫雷

C++
#include <bits/stdc++.h>
#include <Windows.h>
#include <time.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define cmd system
#define cls system("cls")

void ms(double k) {
	k *= 1000;
	Sleep(k);
	return;
}

void color(int c) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

void HideCursor() {
	CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
	curInfo.dwSize = 1; //如果没赋值的话,光标隐藏无效
	curInfo.bVisible = FALSE; //将光标设置为不可见
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //获取控制台句柄
	SetConsoleCursorInfo(handle, &curInfo); //设置光标信息
}

const int N = 30;
int n = 10, m = 10, a[N][N];
int s = n * m / 10, ds = 0;
bool f[N][N], p[N][N];

void gt() {
	cmd("title 扫雷");
	cmd("mode con cols=25 lines=15");
	cmd("color F0");
	srand(time(0));
	memset(p, false, sizeof(p));
	memset(f, false, sizeof(f));
	HideCursor();
	for (int i = 1; i <= s; i++) {
		int rx = rand() % 10 + 1;
		int ry = rand() % 10 + 1;
		if (a[rx][ry] == 0) {
			a[rx][ry] = 11;
		} else {
			i--;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 11)
				continue;
			int ans = 0;
			if (a[i + 1][j] == 11)
				ans++;
			if (a[i - 1][j] == 11)
				ans++;
			if (a[i][j + 1] == 11)
				ans++;
			if (a[i][j - 1] == 11)
				ans++;
			if (a[i + 1][j + 1] == 11)
				ans++;
			if (a[i + 1][j - 1] == 11)
				ans++;
			if (a[i - 1][j + 1] == 11)
				ans++;
			if (a[i - 1][j - 1] == 11)
				ans++;

			a[i][j] = ans;
		}
	}
}

queue<pair<int, int> >q;
int d[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

void bfs(int cx, int cy) {
	q.push({cx, cy});
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		if (f[x][y])
			continue;
		f[x][y] = true;
		if (a[x][y] != 0) {
			continue;
		}
		for (int i = 0; i < 4; i++) {
			int vx = x + d[i][0], vy = y + d[i][1];
			if (vx < 1 || vy < 1 || vx > n || vy > m) {
				continue;
			}
			q.push({vx, vy});
		}
	}
}

void out() {
	cls;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (f[i][j]) {
				if (a[i][j] == 0) {
					color(255);
					cout << "  ";
				} else if (a[i][j] == 11) {
					color(245);
					cout << "* ";
				} else {
					color(240 + a[i][j]);
					cout << a[i][j] << ' ';
				}
			} else {
				if (p[i][j]) {
					color(9 * 16 + 4);
					cout << "P ";
				} else {
					color(9 * 16 + 9);
					cout << "  ";
				}
			}
		}
		color(240);
		cout << i << '\n';
	}
	for (int i = 1; i <= n; i++) {
		cout << i;
		if (i < 10) {
			cout << ' ';
		}
	}
	cout << '\n';
	color(240);
}

int main() {
	gt();
	out();
	do {
		int x, y, op;
		cin >> op >> x >> y;
		if (f[x][y]) {
			out();
			continue;
		}
		if (op == 1) {
			if (p[x][y]) {
				out();
				continue;
			}
			if (a[x][y] == 11) {
				memset(f, true, sizeof(f));
				out();
				break;
				cout << "NO\n";
			} else if (a[x][y]) {
				f[x][y] = true;
			} else {
				bfs(x, y);
			}
			ds++;
		} else if (op == 2) {
			p[x][y] = !p[x][y];
		}
		out();
	} while (ds < n * m);
	return 0;
}

五子棋

C++
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include<bits/stdc++.h>
using namespace std;
/************************************/
int n = 20, m = 20, cnt;
short a[105][105]; 
int colour =  224;
/************************************/

void color(int c) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void ms(int n){
	for(int i=1;i<=n;i++){
		system("timeout /t 1 /nobreak > NUL");
	}
}
void gt(){
	system("mode con cols=42 lines=22");
	system("title 五子棋");
	CONSOLE_CURSOR_INFO curInfo;
	curInfo.dwSize = 1;
	curInfo.bVisible = FALSE;
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorInfo(handle, &curInfo);
}

void out(){
	system("cls");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]==0){
				color(colour);
				if(i==1&&j==1){
					cout << "┌";
				} else if(i==1&&j==m){
					cout << "┐";
				}else if(i==n&&j==1){
					cout << "└";
				}else if(i==n&&j==m){
					cout << "┘";
				}else if(i==1){
					cout << "┬";
				}else if(i==n){
					cout << "┴";
				}else if(j==1){
					cout << "├";
				}else if(j==m){
					cout << "┤";
				}else{
					cout << "┼";
				}
				cout << ' ';
			}else if(a[i][j]==1){
				color(colour);
				cout << "●";
			}else if(a[i][j]==2){
				color(239);
				cout << "●";
			}
		}
		color(colour);
		if(i<10){
			cout << ' ';
		}
		cout << i;
		cout << '\n';
	}
	color(colour);
	for(int i=1;i<=n;i++){
		if(i<10){
			cout << ' ';
		}
		cout << i;
	}
	cout << "  \n";
	color(7);
}

short check(int x, int y){
	if(a[x][y]==a[x+1][y]&&a[x+1][y]==a[x+2][y]&&a[x][y]==a[x-1][y]&&a[x-1][y]==a[x-2][y]){
		if(a[x][y]==1){
			return 1;
		}else{
			return 2;
		}
	}else if(a[x][y]==a[x][y+1]&&a[x][y+1]==a[x][y+2]&&a[x][y]==a[x][y-1]&&a[x][y-1]==a[x][y-2]){
		if(a[x][y]==1){
			return 1;
		}else{
			return 2;
		}
	}else if(a[x][y]==a[x+1][y+1]&&a[x+1][y+1]==a[x+2][y+2]&&a[x][y]==a[x-1][y-1]&&a[x-1][y-1]==a[x-2][y-2]){
		if(a[x][y]==1){
			return 1;
		}else{
			return 2;
		}
	}else if(a[x][y]==a[x+1][y-1]&&a[x+1][y-1]==a[x+2][y-2]&&a[x][y]==a[x-1][y+1]&&a[x-1][y+1]==a[x-2][y+2]){
		if(a[x][y]==1){
			return 1;
		}else{
			return 2;
		}
	}else{
		return 0;
	}
} 

int x, y, ans;
bool now = true;
int main(){
	gt();
	while(cnt<=n*m){
		out();
		cin>>x>>y;
		if(!a[x][y]){
			if(now){
				a[x][y] = 1;
			}else{
				a[x][y] = 2;
			}
			cnt++;
			now = !now;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(a[i][j]){
					ans = check(i, j);
					if(ans){
						out();
						if(ans==1){
							cout << "黑\n";
						} else {
							cout << "白\n";
						}
						system("mode con cols=42 lines=30");
						return 0;
					}
				}
					
			}
		}
	}
	system("mode con cols=42 lines=30");
	cout << "平\n";
	return 0;
}

反应力锻炼4.0

C++
//-------------------------设置----------------------------
//  目标数    时间限制  (-1表示没有)
int bs = -1, bt = -1;
bool Ro = true; //是否有机器人
//颜色:字体     边框      角色     食物     底版   机器人
int c_z = 15, c_k = 15, c_r = 1, c_g = 4, c_d = 0, c_R = 2;
int wat = 5000;//食物等待时间
int Rwait = 150;//机器人的移动间隔时间
//---------------------------------------------------------

#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <bits/stdc++.h>
#define cls system("cls")
#define pause system("pause>NUL")
using namespace std;
inline long long random(int l, int r) {
	if (l == r)
		return l;
	int Mod = abs(r - l + 1);
	return rand() % Mod * rand() % Mod * rand() % Mod + std::min(l, r);
}
inline void CurHide() {//隐藏光标
	CONSOLE_CURSOR_INFO curInfo;
	curInfo.dwSize = 1;
	curInfo.bVisible = FALSE;
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorInfo(handle, &curInfo);
}
inline void color(int a, int b = -1) {//颜色函数
	if (b == -1)
		b = a;
	int c = b * 16 + a;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
inline void CurPos(int x, int y) {//移动光标
	COORD coord = {static_cast<SHORT>(y - 1), static_cast<SHORT>(x - 1)};
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

const int LEN = 25;
int N = 20;
int rx = 1, ry = 1;
int gx, gy;
int last, st;
int sum;
int Rl;
//Robot
int Rx = N, Ry = N;
int Rsum;


int tim() {
	return clock() - st;
}

void out(int x, int y) {
	CurPos(x + 3, 2 * y - 1 + 2);
	if (x == rx && y == ry) {
		color(c_r);
		cout << "  ";
	} else if (Ro && x == Rx && y == Ry) {
		color(c_R);
		cout << "  ";
	} else if (x == gx && y == gy) {
		color(c_g);
		cout << "  ";
	} else {
		color(c_d);
		cout << "  ";
	}
}

void check() {
	if (rx == gx && ry == gy) {
		last = clock();
		sum++;
		CurPos(1, 1);
		color(c_z, 0);
		cout << " 得分 : " << sum;
		gx = random(1, N), gy = random(1 + (gx == 1), N);
		out(gx, gy);
	}
}

void init() {
	cout << "\n\n";
	color(c_k);
	for (int i = 1; i <= N + 2; i++) {
		cout << "  ";
	}
	cout << '\n';
	for (int i = 1; i <= N; i++) {
		cout << "  ";
		for (int j = 1; j <= N; j++) {
			color(c_d);
			cout << "  ";
		}
		color(c_k);
		cout << "  ";
		cout << '\n';
	}
	for (int i = 1; i <= N + 2; i++) {
		cout << "  ";
	}
	for (int i = 1; i < N + 1; i++) {
		out(i, N);
	}
	sum = 0, Rsum = 0;
	st = clock(), last = st, Rl = st;
	CurHide();
	srand((unsigned)time(0));
	gx = random(1, N), gy = random(1 + (gx == 1), N);
	CurPos(1, 1);
	color(c_z, 0);
	cout << " 得分 : " << sum;
	out(rx, ry);
	out(gx, gy);
	if (Ro) {
		color(c_z, 0);
		CurPos(1, 20);
		cout << "机器人得分 : " << Rsum;
		out(Rx, Ry);
	}
}

inline void game() {
	init();
	while (((sum < bs) || bs == -1) && (tim() / 1000 < bt || bt == -1)) {
		if (_kbhit()) {
			char ch = getch();
			if (ch == 'w') {
				if (rx > 1) {
					out(rx--, ry);
					out(rx, ry);
				}
			} else if (ch == 's') {
				if (rx < N) {
					out(rx++, ry);
					out(rx, ry);
				}
			} else if (ch == 'a') {
				if (ry > 1) {
					out(rx, ry--);
					out(rx, ry);
				}
			} else if (ch == 'd') {
				if (ry < N) {
					out(rx, ry++);
					out(rx, ry);
				}
			}
		}
		check();
		if (Ro) {
			if (tim() - Rl >= Rwait) {
				Rl = tim();
				int vx = Rx, vy = Ry;
				if (Rx != gx && Ry != gy) {
					if (random(0, 105) % 3 == 0) {
						Ry += (gy > Ry);
						Ry -= (gy < Ry);
					} else {
						Rx += (gx > Rx);
						Rx -= (gx < Rx);
					}
				} else if (Rx == gx) {
					Ry += (gy > Ry);
					Ry -= (gy < Ry);
				} else if (Ry == gy) {
					Rx += (gx > Rx);
					Rx -= (gx < Rx);
				}
				out(vx, vy);
				out(Rx, Ry);
				if (Rx == gx && Ry == gy) {
					last = clock();
					Rsum++;
					CurPos(1, 20);
					color(c_z, 0);
					cout << " 机器人得分 : " << Rsum;
					gx = random(1, N), gy = random(1 + (gx == 1), N);
					out(gx, gy);
				}
			}
		}
		CurPos(2, 1);
		color(c_z, 0);
		cout << " 时间 : " << tim() / 1000 << "s";
		if (tim() - last > wat || wat == -1) {
			last = tim();
			int vx = gx, vy = gy;
			gx = random(1, N), gy = random(1 + (gx == 1), N);
			out(vx, vy);
			out(gx, gy);
		}
	}
	Sleep(5000);
	system("pause");
}

int main() {
	game();
	return 0;
}

计算器

C++
/********游戏游玩方法******
1.先按下0~9读入第一个数。
2.按下‘+’,‘-’,‘*’,‘/’, 读入计算方法。
3.按下0~9读入第二个数。
4.最后按下‘=’, 显示答案。
**************************/
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <bits/stdc++.h>
using namespace std;

//打印
bool o[10][5][3] = {
	{
		//0
		{1, 1, 1},
		{1, 0, 1},
		{1, 0, 1},
		{1, 0, 1},
		{1, 1, 1}
	}, { //1
		{0, 0, 1},
		{0, 0, 1},
		{0, 0, 1},
		{0, 0, 1},
		{0, 0, 1}
	}, { //2
		{1, 1, 1},
		{0, 0, 1},
		{1, 1, 1},
		{1, 0, 0},
		{1, 1, 1}
	}, { //3
		{1, 1, 1},
		{0, 0, 1},
		{1, 1, 1},
		{0, 0, 1},
		{1, 1, 1}
	}, { //4
		{1, 0, 1},
		{1, 0, 1},
		{1, 1, 1},
		{0, 0, 1},
		{0, 0, 1}
	}, { //5
		{1, 1, 1},
		{1, 0, 0},
		{1, 1, 1},
		{0, 0, 1},
		{1, 1, 1}
	}, { //6
		{1, 1, 1},
		{1, 0, 0},
		{1, 1, 1},
		{1, 0, 1},
		{1, 1, 1}
	}, { //7
		{1, 1, 1},
		{0, 0, 1},
		{0, 0, 1},
		{0, 0, 1},
		{0, 0, 1}
	}, { //8
		{1, 1, 1},
		{1, 0, 1},
		{1, 1, 1},
		{1, 0, 1},
		{1, 1, 1}
	}, { //9
		{1, 1, 1},
		{1, 0, 1},
		{1, 1, 1},
		{0, 0, 1},
		{1, 1, 1}
	}

};

void color(int c) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

//计算
int op = 1;//步骤
char fh; //符号
long long s1;
long long s2;
long long ans;
bool fz = true;

//反转数字
long long f(long long n) {
	long long ans = 0;
	while (n) {
		ans = ans * 10 + (n % 10);
		n /= 10;
	}
	return ans;
}

//位数
int ws(long long n) {
	long long k = n;
	int c = 0;
	if (n == 0) {
		return 1;
	}
	while (k) {
		k /= 10;
		c++;
	}
	return c;
}

//横120, 纵30

//显示数字
void cd(long long n) { //17个数,n < 10^18
	n = n % 100000000000000000;
	int len = ws(n);
	int u;
	long long v;
	for (int k = 0; k < 5; k++) {
		for (int i = 1; i <= (17 - len) * 7; i++) { //空格处理
			cout << " ";
		}
		v = f(n);
		for (int i = 1; i <= len; i++) {
			u = v % 10;
			v /= 10;
			for (int j = 0; j < 3; j++) {
				if (o[u][k][j]) {
					cout << "■";
				} else {
					cout << "  ";
				}
			}
			cout << " ";
		}
		cout << "\n";
	}
	return;
}

void HideCursor() {
	CONSOLE_CURSOR_INFO curInfo; //定义光标信息的结构体变量
	curInfo.dwSize = 1; //如果没赋值的话,光标隐藏无效
	curInfo.bVisible = FALSE; //将光标设置为不可见
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); //获取控制台句柄
	SetConsoleCursorInfo(handle, &curInfo); //设置光标信息
}

//输出
void out() {
	system("cls");
	for (int i = 1; i <= 50; i++) {
		cout << " ";
	}
	cout << fh;
	for (int i = 1; i <= 50; i++) {
		cout << " ";
	}
	if (!fz) {
		cout << "ans < 0";
	}
	cout << '\n';
	if (op == 3) {
		cd(s2);
	} else if (op <= 2) {
		cd(s1);
	} else if (op == 4) {
		cd(ans);
	}
}
int ch;

int main() {
	HideCursor();
	system("color 0a");
	system("title 计算器");
	system("mode con cols=120 lines=10");
	while (1) {
		ch = getch();
		switch (ch) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				if (op == 1) {
					s1 *= 10;
					s1 += ch - '0';
				} else if (op == 3) {
					s2 *= 10;
					s2 += ch - '0';
				} else if (op == 2) {
					op = 3;
					s2 = 0;
					s2 += ch - '0';
				}
				s1 = s1 % 100000000000000000;
				s2 = s2 % 100000000000000000;
				break;
			case 'P':
				if (op == 1) {
					s1 /= 10;
				} else if (op == 3) {
					s2 /= 10;
				}
				break;
			case '+':
				if (op == 1) {
					op = 2;
					fh = ch;
				}
				break;
			case '-':
				if (op == 1) {
					op = 2;
					fh = ch;
				}
				break;
			case '*':
				if (op == 1) {
					op = 2;
					fh = ch;
				}
				break;
			case '/':
				if (op == 1) {
					op = 2;
					fh = ch;
				}
				break;
			case '=':
				if (op == 3) {
					op = 4;
					if (fh == '+') {
						ans = s1 + s2 % 100000000000000000;
					} else if (fh == '-') {
						if (s1 > s2) {
							ans = s1 - s2 % 100000000000000000;
						} else {
							ans = s2 - s1 % 100000000000000000;
							fz = false;
						}
					} else if (fh == '*') {
						ans = s1 * s2 % 100000000000000000;
					} else if (fh == '/') {
						if (s2 != 0) {
							ans = s1 / s2 % 100000000000000000;
						} else {
							system("cls");
							cout << "错误\n";
							return 0;
						}
					}
				}
				out();
			case '#':
				return 0;
		}
		out();
	}
	return 0;
}

计算器2.0

C++
//输入一个四则运算算式(不带括号), 返回结果
#include <bits/stdc++.h>
using namespace std;
#define int long double

stack<int>st;
int ans;
int x, k;
char op;

signed main() {
	cin >> x;
	st.push(x);
	while (cin >> op) {
		cin >> x;
		if (op == '+') {
			st.push(x);
		} else if (op == '-') {
			st.push(-x);
		} else if (op == '*') {
			k = st.top();
			st.pop();
			k *= x;
			st.push(k);
		} else if (op == '/') {
			k = st.top();
			st.pop();
			k /= x;
			st.push(k);
		}
	}
	while (!st.empty()) {
		ans += st.top();
		st.pop();
	}
	cout << ans << '\n';
	return 0;
}

井字棋

C++
/********游戏游玩方法*******
1.通过按
7 8 9
4 5 6
1 2 3
2.来下棋, 会自动判断输赢
***************************/
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include<bits/stdc++.h>
namespace game{
	//颜色设置
	void color(int c) {
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
	}
	void ms(int n){
		for(int i=1;i<=n;i++){
			system("timeout /t 1 /nobreak > NUL");
		}
	}
	void gt(){
		srand(time(0));
		CONSOLE_CURSOR_INFO curInfo;
		curInfo.dwSize = 1;
		curInfo.bVisible = FALSE;
		HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleCursorInfo(handle, &curInfo);
		system("title ");
		system("mode con cols=120 lines=35");
	}
}
using namespace std;
using namespace game;

/*********bl*********/
int a[3][3] = {{0, 0, 0},{0, 0, 0},{0, 0, 0}};
bool b[3][3] = {{0, 0, 0},{0, 0, 0},{0, 0, 0}};
int f = 1;
int cnt; 
/********************/

string ans = "平"; 

void out(){
	system("cls");
	color(102);
	for(int i=0;i<31;i++){
		cout << "■";
	} 
	cout << '\n';
	for(int i=1;i<30;i++){
		color(102);
		cout << "■";
		for(int j=1;j<30;j++){
			if(a[i/10][j/10]==0){
				color(102);
			}else if(a[i/10][j/10]==1){
				color(0);
			}else if(a[i/10][j/10]==2){
				color(255);
			}
			cout << "■"; 
		}
		color(102);
		cout << "■";
		color(15);
		cout << '\n';
	}
	color(102);
	for(int i=0;i<31;i++){
		cout << "■";
	} 
	color(15);
	return;
}

int op, ch;
int x, y;
signed main(){
	gt();
	out();
	while(cnt < 9){
		op = getch();
		if(op>='1'&&op<='9'){
			if(op=='1'){
				x = 2, y = 0;
			}else if(op=='2'){
				x = 2, y = 1;
			}else if(op=='3'){
				x = 2, y = 2;
			}else if(op=='4'){
				x = 1, y = 0;
			}else if(op=='5'){
				x = 1, y = 1;
			}else if(op=='6'){
				x = 1, y = 2;
			}else if(op=='7'){
				x = 0, y = 0;
			}else if(op=='8'){
				x = 0, y = 1;
			}else if(op=='9'){
				x = 0, y = 2;
			}
		}
		if(!b[x][y]){
			cnt++;
			b[x][y] = true;
			a[x][y] = f;
			if(f == 2){
				f--;
			}else{
				f++;
			}
		}
		if(cnt >= 5){
			if(a[0][0]==a[0][1]&&a[0][1]==a[0][2]){
				if(a[0][0] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[0][0] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[1][0]==a[1][1]&&a[1][1]==a[1][2]){
				if(a[1][0] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[1][0] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[2][0]==a[2][1]&&a[2][1]==a[2][2]){
				if(a[2][0] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[2][0] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[0][0]==a[1][0]&&a[1][0]==a[2][0]){
				if(a[0][0] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[0][0] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[0][1]==a[1][1]&&a[1][1]==a[2][1]){
				if(a[0][1] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[0][1] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[0][2]==a[1][2]&&a[1][2]==a[2][2]){
				if(a[0][2] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[0][2] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]){
				if(a[1][1] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[1][1] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}else if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]){
				if(a[1][1] == 1){
					ans = "黑方胜";
					out();
					break;
				}else if(a[1][1] == 2){
					ans = "白方胜";
					out();
					break;
				}
			}
		}
		out();
	}
	cout <<'\n'<< ans << '\n';
	return 0;
}

高精除低精

C++
#include <bits/stdc++.h>
using namespace std;
string s;
int k, tmp, len, i;
bool out, z, d;
bool fzs = 1, fzk = 1;

int main() {
	cin >> s >> k;
	if (s[0] == '-') {
		s = s.substr(1, s.size() - 1);
		fzs = false;
	}
	if (k < 0) {
		k = abs(k);
		fzk = false;
	}
	len = s.size();
	if (fzs != fzk) {
		cout << '-';
	}
	do {
		if ((s[i] == '.' || i == len) && !d) {
			if (!z) {
				cout << '0';
				z = true;
			}
			d = true;
			cout << '.';
			continue;
		}
		tmp *= 10;
		if (i < len) {
			tmp += (s[i] - '0');
			i++;
		}
		if (tmp / k || out) {
			z = true;
			out = true;
			cout << tmp / k;
			tmp %= k;
		}
	} while (tmp || i < len);
	cout << '\n';
	return 0;
}

编辑

原文