跳到正文

科技·工程

造数据器

NOl_O2约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年5月19日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;

// 通用函数:根据编号生成对应的.in和.out文件,并写入内容(直到读取到###为止)
void writeFiles(int num) {
    // 生成文件名(如"1.in"、"1.out")
  string inFile = to_string(num) + ".in";
  string outFile = to_string(num) + ".out";
    
    // 写入.in文件
  ofstream outIn(inFile);
  string s;
  while (true) {
    getline(cin, s);
    if (s == "###") break;
    outIn << s << "\n";
  }
  
  // 写入.out文件
  ofstream outOut(outFile);
  while (true) {
    getline(cin, s);
    if (s == "###") break;
    outOut << s << "\n";
  }
}

signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n; // 测试点个数
  cin >> n;
  // 读取cin后的换行符,避免影响后续getline
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  
  for (int x = 1; x <= n; ++x) {
    writeFiles(x);
  }
  return 0;
}
原文