做题时随手写了一个
#include <bits/stdc++.h>
#include <windows.h>
// #include<conio.h>
using namespace std;
ifstream fin;
ofstream fout;
// int n;
int n,
m, times;
int zhu[55][500];
int top[55]; //每个柱子顶部的位置
bool flag[1100];
void move_(int x, int y)
{
zhu[y][++top[y]] = zhu[x][top[x]--];
}
int main()
{
fout.open("P7115-SPJ-运行结果.txt");
cout << "请输入 题目输入 的文件名(要带文件后缀)\n";
char file1[114514]; //输入
cin >> file1;
cout << "请输入 选手输出 的文件名(要带文件后缀)\n";
char file2[114514]; //选手输出
cin >> file2;
// cout << file1 << "\n";
// cout << file2 << "\n";
fin.open(file1);
if (!fin)
{
fout << "打开 题目输入 文件失败,请检查输入文件是否存在\n";
cout << "打开 题目输入 文件失败,请检查输入文件是否存在\n";
system("pause");
}
fin >> n >> m;
for (int w = 1; w <= n; w++)
{
top[w] = m;
for (int ww = 1; ww <= m; ww++)
{
fin >> zhu[w][ww];
}
}
fin.close();
fin.open(file2);
if (!fin)
{
fout << "打开 选手输出 文件失败,请检查 选手输出 是否存在\n";
cout << "打开 选手输出 文件失败,请检查 选手输出 是否存在\n";
system("pause");
}
fin >> times;
cout << times << "\n";
int a, b;
bool wsw = 1;
for (int yy = 1; yy <= times; yy++)
{
fin >> a >> b;
if (top[a] == 0)
{
fout << "操作 " << yy << " ";
fout << "在从 " << a << " 移动到" << b << " 时 " << a << " 为 空!\n";
cout << "操作 " << yy << " ";
cout << "在从 " << a << " 移动到" << b << " 时 " << a << " 为 空!\n";
wsw = 0;
}
else if (top[b] >= m)
{
fout << "操作 " << yy << " ";
fout << "在从 " << a << " 移动到" << b << " 时 " << b << " 溢出\n";
cout << "操作 " << yy << " ";
cout << "在从 " << a << " 移动到" << b << " 时 " << b << " 溢出\n";
wsw = 0;
}
move_(a, b);
}
for (int ww = 1; ww <= n; ww++)
{
if (top[ww] != m)
{
// cout<<"操作 "<< yy<<" ";
fout << ww << " 中的数量不足!\n";
cout << ww << " 中的数量不足!\n";
wsw = 0;
}
}
int tmp;
for (int rr = 1; rr <= n; rr++)
{
tmp = zhu[rr][1];
for (int ww = 1; ww <= m; ww++)
{
if (zhu[rr][ww] != zhu[rr][1])
{
fout << "第 " << rr << " 号柱子上有颜色不同的球\n";
cout << "第 " << rr << " 号柱子上有颜色不同的球\n";
wsw = 0;
}
}
}
if (wsw)
{
MessageBox(NULL, "NB 你做对了\n", "AC", MB_OK);
fout << "NB 你做对了\n";
cout << "NB 你做对了\n";
}
fout << endl
<< "\n";
cout << endl
<< "\n";
fout << "你的程序的最终操作结果为:\n";
cout << "你的程序的最终操作结果为:\n";
for (int rr = 1; rr <= n; rr++)
{
// tmp = zhu[rr][1];
for (int ww = 1; ww <= m; ww++)
{
fout << zhu[rr][ww] << " ";
cout << zhu[rr][ww] << " ";
}
fout << "\n";
cout << "\n";
}
MessageBox(NULL, "SPJ运行结果已保存在文件中\n", "SPJ", MB_OK);
}