如何解决运行时错误C ++ USACO培训-“运行1:执行错误:您的程序出现以下运行时错误:非法文件打开gift1.out”
我一直在尝试USACO培训页面问题,并且收到一个运行时错误,指出“运行1:执行错误:您的程序出现以下运行时错误: 非法文件打开(gift1.out)。程序运行0.004 CPU 错误发生前的秒数。它使用了1336 KB的内存。 ” 这是代码
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream outfile ("gift1.out");
ofstream fout ("gift1.out");
ifstream fin ("gift1.in");
int numPeople;
string currentGiver;
string currentRec;
int perPerson;
int forGiver;
fin >> numPeople;
string name[numPeople];
float amount[numPeople];
float recNum[numPeople];
int money[numPeople];
for (int i = 0; i < numPeople; i++){
fin >> name[i];
money[i] = 0;
}
for (int j = 0; j < numPeople; j++){
fin >> currentGiver;
for (int i = 0; i < numPeople; i++){
if (currentGiver == name[i]){
fin >> amount[i];
fin >> recNum[i];
perPerson = amount[i]/recNum[i];
forGiver = amount[i] - (perPerson * recNum[i]);
money[i] += forGiver;
money[i] -= amount[i];
for (int k = 0; k < recNum[i]; k++){
fin >> currentRec;
for (int m = 0; m < numPeople; m++){
if (currentRec == name[m]){
money[m] += (perPerson);
}
}
}
}
}
}
for (int i = 0; i < numPeople; i++){
fout << name[i] << " " <<money[i] << endl;
}
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。