實在是無法忍受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;elsedo{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;elsedo{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;}}
}