⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nhfang.cpp

📁 功能:四阶幻方全解 运算时间:3、40秒 结果:7040个 环境:Visual Studio.net 2003的vc++的控制台项目
💻 CPP
字号:
// NHFang.cpp : 定义控制台应用程序的入口点。
//V2.0
//开始时间:2004-05-15日左右
//完成时间:2004-05-23
//本程序共用四个类:stack,sqlist,matrix,result。
//stack类定义栈类模板,用于sqlist类和matrix类中。
//sqlist类用于求1~DIM*DIM中相加等于SUM(四阶为34)的四个不同的数---行(四阶时共有86行),方法是非递归的回溯法(用栈)。
//matrix类用于求包含全部1~DIM*DIM的行---组(四阶时有392组),方法是非递归的回溯法(用栈)。
//result类求出全部幻方的结果(四阶时共有7040个),方法是对matrix中的每一组先对每一行的元素进行排列,
//然后进行组合,同时对每一组合进行行排列,对每一排列结果进行判断。

#include "stdafx.h"
#include <iostream>
#include <tchar.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
#include "stack.h"
#include "sqlist.h"
#include "matrix.h"
#include "result.h"

//using namespace std;
////////////////////////////////主函数////////////////////////////////
int _tmain(int argc, _TCHAR* argv[])
{
	
	/*Matrix m1;
	m1.CountAllMatrix();
	cout << m1.GetMLength() << endl;*/
	Result rt;
	rt.CountAllResult();	
	cout << "共有 " << rt.GetRLength() << "个结果" << endl;
	system("pause");
	int from,to;
	char yn;
	while(true)
	{
		system("cls");
		cout << "请输入要显示结果的范围[1, " << rt.GetRLength() << "]" << endl;
		cout << "从第几组:" ;
		cin >> from;
		cout << "到第几组:";
		cin >> to;
		if ((from > 0 && from <= rt.GetRLength()) && (to > 0 && to <= rt.GetRLength()) && from <= to)
		{
			rt.DisplayScope(from, to);
			cout << endl;
			system("pause");
		}
		else
		{
			continue;
		}
		while(true)
		{
			system("cls");
			cout << "是否继续(Y/N)?" ;
			cin >> yn;
			if (yn == 'N'|| yn == 'n' || yn == 'Y' || yn == 'y')
			{
				break;
			}
		}
		if (yn == 'N' || yn == 'n')
		{
			break;
		}
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -