|
发表于 2020-7-23 12:39:24
|
显示全部楼层
本楼为最佳答案
本帖最后由 永恒的蓝色梦想 于 2020-7-23 14:05 编辑
你看这行不行?
- #include<fstream>
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- constexpr char file_path[] = "C:\\Users\\XXX\\Desktop\\0.txt";
- ofstream file(file_path);
- void func() {
- switch (rand() & 3) {
- case 0:
- file << rand() % 1000 << '+' << rand() % 1000;
- break;
- case 1:
- file << rand() % 1000 << '-' << rand() % 1000;
- break;
- case 2:
- file << rand() % 100 << '*' << rand() % 100;
- break;
- case 3:
- file << rand() % 100 << '/' << rand() % 99 + 1;
- break;
- }
- }
- int main() {
- ios::sync_with_stdio(false);
- int mcount;
- cout << "输入题量:";
- cin >> mcount;
- file << "解决下列问题:\n";
- for (int count = 1; count < mcount; count += 2) {
- file << '\n' << '#' << count << ". #" << count + 1 << ".\n ___ ___\n ";
- func();
- file << " ";
- func();
- file << '\n' << '\n';
- }
- if (mcount & 1) {
- file << '\n' << '#' << mcount << ".\n ___\n ";
- func();
- }
- file.close();
- return 0;
- }
复制代码 代码里的 file_path 改成自己的。 |
|