我想把输入的n个地毯信息先写到一个文件里,再读出最后要找的x,y,然后根据xy去找哪个地毯最终盖住了这块区域
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int n;
cin >> n;
int a, b, c, d;
ofstream outfile("temp.txt", ios::out);
for (int i = 0;i < n;i++)
{
cin >> a >> b >> c >> d;
outfile << a << " " << b << " " << c << " " << d << endl;
}
int x, y;
cin >> x >> y;
outfile.close();
ifstream infile("temp.txt", ios::in);
int overlap = -1;
for (int i = 1;i <= n;i++)
{
infile >> a >> b >> c >> d;
if (x >= a && y >= b && x < a + c && y < b + d) overlap = i;
}
infile.close();
cout << overlap << endl;
return 0;
}
然后喜提9个WA(哭
求助!真的没懂TAT