第十一届蓝桥杯大赛第二场省赛试题 C&C++ 研究生组-蛇形填数

761

solution1

cpp 复制代码
#include<stdio.h>
int main(){
	int a[50][50] = {0}, i = 1, j = 1, count = 1, op = 0;
	while(i < 40 && j < 40){
		a[i][j] = count++;
		if(!op) a[i][++j] = count++;
		while(j >= 2){
			a[++i][--j] = count++;
		}
		a[++i][j] = count++;
		while(i >= 2){
			a[--i][++j] = count++;
		}
		j++;
		op = 1;
	}
//	for(int i = 1; i < 21; i++){
//		for(int j = 1; j < 21; j++){
//			printf("%d ", a[i][j]);
//		}
//		printf("\n");
//	}
	printf("%d", a[20][20]);
	return 0;
}

solution2

cpp 复制代码
#include<stdio.h>
int main(){
	int a[50][50] = {0}, i = 1, j = 1, count = 1, op = 0;
	a[1][1] = count++;
	while(i < 40 && j < 40){
		a[i][++j] = count++;
		while(j >= 2){
			a[++i][--j] = count++;
		}
		a[++i][j] = count++;
		while(i >= 2){
			a[--i][++j] = count++;
		}
	}
//	for(int i = 1; i < 21; i++){
//		for(int j = 1; j < 21; j++){
//			printf("%d ", a[i][j]);
//		}
//		printf("\n");
//	}
	printf("%d", a[20][20]);
	return 0;
}
相关推荐
hetao173383721 分钟前
2025-12-12~14 hetao1733837的刷题笔记
数据结构·c++·笔记·算法
椰子今天很可爱25 分钟前
五种I/O模型与多路转接
linux·c语言·c++
程序员zgh1 小时前
C++ 互斥锁、读写锁、原子操作、条件变量
c语言·开发语言·jvm·c++
喵了meme1 小时前
C语言实战5
c语言·开发语言
獭.獭.3 小时前
C++ -- STL【unordered_set和unordered_map的使用】
c++·stl·unordered_map·unordered_set
神仙别闹3 小时前
基于C语言实现B树存储的图书管理系统
c语言·前端·b树
star _chen4 小时前
C++ std::move()详解:从小白到高手
开发语言·c++
福尔摩斯张4 小时前
C++核心特性精讲:从C语言痛点出发,掌握现代C++编程精髓(超详细)
java·linux·c语言·数据结构·c++·驱动开发·算法
charlie1145141914 小时前
如何快速在 VS2026 上使用 C++ 模块 — 完整上手指南
开发语言·c++·笔记·学习·现代c++
报错小能手5 小时前
STL_unordered_map
开发语言·c++·哈希算法