【18位数据次方提高数据输出速度】2022-3-9

实在是无法忍受W10输出数据那么慢W7需要2分钟输出数据W10则需要10分钟完成W7需要3分钟W10则需要15分钟完成输出数据,虽然W10运算速度比W7快很多但是加上输出速度总体完成时间居然差不多!随着使用数组超过百万W7数据输出时间也变长,随着数组数据超百万每运算1万次方历时也变得较长,快速保存每次运算好的数据很有必要,只好再次出手,写提高输出文本速度只能用尾部叠加法不能用插入法和叠加头部法:

void 二的次方数组(_int64* 数, _int64 长, _int64 次)
{
	_int64 溢 = 0, 序 = 长 - 1, 次方 = 1; std::string wb = "";
	二的次方数组读取文本("..\\Debug\\回复专用\\", "二次方数据*.txt", 数, 长, 次方);
	char 时间[128]; _strtime_s(时间, 128); printf("时间:%s 次方%d\n", 时间, 次方);
	if (次方 == 1)数[序] = 1; else;
	while (次方 && 序 > -1)
	{
		if (数[序] > 0)
		{
			数[序] = 数[序] * 2 + 溢;
			溢 = 数[序] / 1E+18;
			数[序] -= 溢*1E+18;
			if (次方 % 40000 == 0)
				wb += std::to_string(数[序]) + "\n"; else;
			--序;
		}
		else
		{
			数[序] += 溢;
			if (wb != "")
			{
				if (溢> 0)wb += std::to_string(数[序]) + "\n"; else;
				_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << 次方 << " " << 长 - 序;
				写入文本("..\\Debug\\回复专用\\二次方数据倒序" + std::to_string(次方 + 1) + ".txt", wb/* + std::to_string(序)*/);
				_strtime_s(时间, 128); printf(":%s数据输出完成。\n", 时间); wb = "";
			}else;
			if (++次方 > 次 || 数[0] > 0)
			{
				_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << 次方 << " " << 长 - 序;
				写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(序) + "\n");
				while (++序 < 长)
					写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(数[序]) + "\n");
				_strtime_s(时间, 128); printf(":%s数据输出完成。\n", 时间);
				次方 = 0;
			}else;
			if (次方 % 10000 == 0)
			{
				string 标题 = "VsC++:" + std::to_string(次方) + "编程论坛回复专用=》VsC++:二次方数组1E7。";
				system(("title " + 标题).data());
			}else;
			序 = 长 - 1; 溢 = 0;
		}
	}
}
void 二的次方数组读取文本(std::string 路径, std::string 文件名, _int64* 数, _int64 长, _int64& 次方)
{
	_finddata_t file;
	std::string newPath = 路径 + 文件名, 读取 = "";
	_int64 cf = 0; int j = 0, jj = 0;
	intptr_t HANDLE = _findfirst((路径 + 文件名).c_str(), &file);
	if (HANDLE == -1L)
		std::cout << "无法匹配文件夹路径" << std::endl;
	else
		do
		{
			if (file.attrib)
			{
				newPath = 路径 + file.name;
				j = newPath.find("数据") + 4;
				if (newPath.find("倒序") != std::string::npos)
					j = newPath.find("倒序") + 4;
				jj = newPath.find(".txt");
				cf = _atoi64(newPath.substr(j, jj - j).c_str());
				if (次方 < cf)
					次方 = cf, 读取 = newPath; else;
			}
			else;
		} while (_findnext(HANDLE, &file) == 0);
		_findclose(HANDLE);
		std::string 读 = ""; bool k = (读取.find("倒序") == std::string::npos);
		int 序 = (k ? 0 : 长 - 1), 位 = 0;
		std::ifstream 文件(读取);
		if (!文件.eof())
		{
			while (getline(文件, 读))
				if (k)
				{
					if (序 == 0)
						序 = _atoi64(读.c_str());
					else
						数[++序] = _atoi64(读.c_str());
				}
				else
				{
					数[序] = _atoi64(读.c_str());
					--序;
				}
			//if (!k)数[++序] = 0;
			文件.close();
		}
		else;
		//std::cout << 数[k ? 序 : ++序] << "\t" << 读 << "\n";
        std::cout << 数[k ? 序 : ++序] << "\t" << 读 << "\t" << 数[长 - 1] << "\n";
}

文本名称的次方数-1为实际次方,内容顺序文件第一行为数组序,倒序结尾无数组序。

void 二的次方数组读取文本(std::string 路径, std::string 文件名, _int64 (*数)[10000000], int 长, _int64& 次方)
{
	_finddata_t file;
	std::string newPath = 路径 + 文件名, 读取 = "";
	_int64 cf = 0; int j = 0, jj = 0;
	intptr_t HANDLE = _findfirst((路径 + 文件名).c_str(), &file);
	if (HANDLE == -1L)
		std::cout << "无法匹配文件夹路径" << std::endl;
	else
	do
	{
		if (file.attrib)
		{
			newPath = 路径 + file.name;
			j = newPath.find("数据") + 4;
			if (newPath.find("倒序") != std::string::npos)
				j = newPath.find("倒序") + 4;
			jj = newPath.find(".txt");
			cf = _atoi64(newPath.substr(j, jj - j).c_str());
			if (次方 < cf)
				次方 = cf, 读取 = newPath; else;
		}
		else;
	} while (_findnext(HANDLE, &file) == 0);
	_findclose(HANDLE);
	std::string 读 = "";
	bool k = (读取.find("倒序") == std::string::npos);
	_int64 序 = (k ? 0 : 长 - 1), 位 = 0, 组 = 0;
	std::ifstream 文件(读取);
	if (!文件.eof())
	{
		while (getline(文件, 读))
		if (k)
		{
			if (序 == 0)
				序 = _atoi64(读.c_str());
			else
			{
				//if (序 == 长 && 组 < 1)++组, 序 = 长 - 1;
				数[组][++序] = _atoi64(读.c_str());
			}
		}
		else
		{
			数[组][序] = _atoi64(读.c_str());
			if (--序 < 0 && 组 < 1) ++组, 序 = 长 - 1;//--序;
		}
		文件.close();
	}
	else;
	//std::cout << 数[组][序] << "\t" << 读 << "\n";
	std::cout << 数[组][k ? 序 : ++序] << "\t" << 读 << "\t" << 数[组][长 - 1] << "\n";
}
void 二的次方数组(_int64 (*数)[10000000], _int64 长, _int64 次)
{
	_int64 溢 = 0, 序 = 长 - 1, 次方 = 1, 组 = 0; std::string wb = "";
	二的次方数组读取文本("..\\Debug\\回复专用\\", "二次方数据*.txt", 数, 长, 次方);
	char 时间[128]; _strtime_s(时间, 128); printf("时间:%s 次方%d\n", 时间, 次方);
	if (次方 == 1)数[组][序] = 1; else;
	while (次方 && 序 > -1)
	{
		if (数[组][序] > 0)
		{
			数[组][序] = 数[组][序] * 2 + 溢;
			溢 = 数[组][序] / 1E+18;
			数[组][序] -= 溢*1E+18;
			if (次方 % 40000 == 0) wb += std::to_string(数[组][序]) + "\n"; else;
			if (--序 < 0 && 组 < 1) ++组, 序 = 长 - 1;// --序;
		}
		else
		{
			数[组][序] += 溢;
			if (wb != "")
			{
				if (溢> 0)wb += std::to_string(数[组][序]) + "\n"; else;
				_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << 次方 << " " << 长 - 序;
				写入文本("..\\Debug\\回复专用\\二次方数据倒序" + std::to_string(次方 + 1) + ".txt", wb/* + std::to_string(序)*/);
				_strtime_s(时间, 128); printf(":%s数据输出完成。\n", 时间); wb = "";
			}
			else;
			if (++次方 > 次 || 数[组][0] > 1E+18)// || 次方 % 100000 == 0
			{
				_strtime_s(时间, 128); printf("时间:%s ", 时间); std::cout << "次方" << 次方 << " 数量" << 长 - 序 << " ";
				写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(序) + "\n");
				while (++序 < 长)
				{
					写入文本("..\\Debug\\回复专用\\二次方数据" + std::to_string(次方) + ".txt", std::to_string(数[组][序]) + "\n");
					显示进度(长, 序);
				}
				_strtime_s(时间, 128); printf(":%s数据保存完成。\n", 时间);
				//if (次方 > 次 || 数[组][0] > 1E+18)
					次方 = 0;
			}
			if (次方 % 10000 == 0)
			{
				std::string 标题 = "VsC++:" + std::to_string(次方);
				system(("title " + 标题).data());
			}
			序 = 长 - 1; 组 = 溢 = 0;
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值