第十一届蓝桥杯大赛第二场省赛试题 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;
}
相关推荐
九久。2 分钟前
手动实现std:iterator/std:string/std::vector/std::list/std::map/std:set
c++·stl
小羊羊Python4 分钟前
Sound Maze - 基于 SFML+C++14 的音效迷宫开源游戏 | MIT 协议
c++·游戏·开源
txinyu的博客12 分钟前
HTTP服务实现用户级窗口限流
开发语言·c++·分布式·网络协议·http
代码村新手13 分钟前
C++-类和对象(上)
开发语言·c++
txinyu的博客24 分钟前
map和unordered_map的性能对比
开发语言·数据结构·c++·算法·哈希算法·散列表
mjhcsp1 小时前
C++ 后缀数组(SA):原理、实现与应用全解析
java·开发语言·c++·后缀数组sa
hui函数1 小时前
如何解决 pip install 编译报错 ‘cl.exe’ not found(缺少 VS C++ 工具集)问题
开发语言·c++·pip
码农小韩1 小时前
基于Linux的C++学习——循环
linux·c语言·开发语言·c++·算法
消失的旧时光-19431 小时前
C++ 命名空间 namespace 讲透:从 std:: 到工程实践
开发语言·c++
程序员Jared1 小时前
C++11—thread库
c++·thread