• 注册
  • APC编程社群 APC编程社群 关注:10 内容:16

    比较有用的测试数据生成+获取

  • 查看作者
  • 打赏作者
    • 社长
      L01

      不废话,直接上代码(拷贝就行)

      主要是改solve

      //#include "read.h"
      #include <Windows.h>
      #include <fstream>
      #include <cmath>
      #include <iostream>
      #include <string>
      using namespace std;
      fstream f1;
      string ans[10001];
      int* ap = new int[100001];
      int ln;
      void open_file_read(string fname) {
      	f1.open(fname.c_str(), ios::in);//以读的方式打开 
      	if (!f1) {//文件不存在 
      		cout << "读取文件" + fname + "失败!" << endl;
      	}
      }
      void read_test(fstream& fin) {
      	int n;
      	while (fin >> n) {
      		ap[0] = n;
      		for (int i = 0; i < n; i++) {
      			fin >> ap[i+1];
      		}
      	}
      }
      string plusall(int n, int _Radix) {
      	double ret = 0;
      	char tmp[16];
      	sprintf_s(tmp, "%d", n);
      	int cnt = strlen(tmp);
      	int j = cnt - 1;
      	for (int i = 0; i < cnt && j >= 0; i++, j--) {
      		ret += (tmp[j] - '0') * pow(_Radix, i);
      	}
      	return to_string((int)ret);
      }
      void solve() {
      	//...
      }
      void write_ans(fstream& fout,int len) {
      	for (int i = 0; i < len; i++) {
      		fout << ans[i] << endl;
      	}
      }
      void open_file_write(string fname) {
      	f1.open(fname.c_str(), ios::in);//以读的方式打开 
      	if (!f1) {//文件不存在 
      		f1.close();
      		f1.open(fname.c_str(), ios::out);//则创建它
      		if (!f1)cout << "创建失败" << endl;
      	}
      	else {//存在 
      		f1.close();
      		f1.open(fname.c_str(), ios::out | ios::trunc);//将文件清空再打开 
      	}
      	cout << "打开文件" + fname << endl;
      }
      int main() {
      	open_file_read("file.in");
      	read_test(f1);
      	//ln = ap[0];
      	cout << "计算结果并输出中..." << endl;
      	for (int i = 1; i <= 1; i++) {
      		clock_t time_stt = clock();
      		//solve
      		cout << "完成数量: " << i + 1 << "  完成率: " << 100.0 / ap[0] * i << endl;
      		cout << "完成时间: " << 1000 * (clock() - time_stt) / (double)CLOCKS_PER_SEC << "ms" << endl;
      	}
      	open_file_write("file.out");
      	write_ans(f1, 1);
      	cout << "file.out输出完毕!";
      	return 0;
      }

      生成

      #include <fstream>
      #include <cstdio>
      #include <iostream>
      #include <ctime>
      #include <string>
      using namespace std;
      fstream f1;
      void write_test(fstream& fout,int fw) {
      	int t = /*rand() % 1 + 2*/1;
      	while (t--) {
      		int n = rand() % 1000 + 1;
      		fout << n << " ";
      		for (int i = /*0*/0; i /* <=*/ <= 3; i++)
      			fout << rand() % (int)(fw) << " ";
      		fout << endl;
      	}
      }
      void open_file_write(string fname) {
      	f1.open(fname.c_str(), ios::in);//以读的方式打开 
      	if (!f1) {//文件不存在 
      		f1.close();
      		f1.open(fname.c_str(), ios::out);//则创建它
      		if (!f1)cout << "创建失败" << endl;
      	}
      	else {//存在 
      		f1.close();
      		f1.open(fname.c_str(), ios::out | ios::trunc);//将文件清空再打开 
      	}
      	cout << "打开文件" + fname << endl;
      }
      int main() {
      	char file_name[50];
      	int fw;
      	cout << "请输入范围: ";
      	cin >> fw;
      	for (int i = 1; i <= 5; i++) {
      		sprintf_s(file_name, "test%d.txt", i);
      		open_file_write(file_name);
      		write_test(f1,fw);
      		f1.close();
      	}
      	return 0;
      }

      亲测有效,如有问题请留言!

      L81
      无敌校草
      你几年级了?这太多人都看不懂的,你太厉害啦! [s-68]

      中土大地,万物峥嵘。

      回复
      L07
      童年才俊

      C++的solve函数,



      云淡风轻的男孩纸。

    • 魏启轩?
      拉黑 2年前 电脑端回复
    • 回复
      L81
      无敌校草
      你好厉害哟! [s-68]

      中土大地,万物峥嵘。

      回复

      请登录之后再进行评论

      登录
      • 社长
      • 副社长
    • 7TN57
    • 魏启轩
    • 暂没有数据

      • 回帖总排行
      • 采纳总排行
    • 朱策
      朱策
      874次回帖
    • 招来风
      招来风
      580次回帖
    • 巡视员
      巡视员
      472次回帖
    • 傅瑾
      傅瑾
      375次回帖
    • 雅典娜的布灵诊所
    • 墨儿
      墨儿
      222次回帖
    • 昭昭暮兮
      昭昭暮兮
      210次回帖
    • 祁絮
      祁絮
      205次回帖
    • 举一桐
      举一桐
      199次回帖
    • 怪而无才
      怪而无才
      187次回帖
    • 秦岭小娃
      秦岭小娃
      151次回帖
    • 股尾前科
      股尾前科
      135次回帖
    • LQM
      LQM
      126次回帖
    • 森屿
      森屿
      120次回帖
    • 将离~
      将离~
      112次回帖
    • 童小蜜
      童小蜜
      108次回帖
    • 祁絮
      祁絮
      1次被采纳
    • 王大大
      王大大
      1次被采纳
    • 招来风
      招来风
      1次被采纳
    • 朱策
      朱策
      1次被采纳
    • 怪而无才
      怪而无才
      1次被采纳
    • 把本页链接发给外网好友获得童年币:

    • 任务
    • AI聊天
    • 客服
    • 偏好
    • 到底部
    • 帖子间隔 侧栏位置: