c++11 - 当我使用 fout 而不是 cout 时,我的代码会打印一个不同的数字
问题描述
嘿,所以我正在做这个练习,我发现当你使用 fout 而不是 cout 时,它会打印一个不同的数字,而你必须打印我在代码示例中设置的东西,如果你输入
14 -783 421 693
-153 680 443 741
作为输入
它将计算出 595441
它会输出 0595441
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream fin("billboard.in");
ofstream fout("billboard.out");
int x1,y1,x2,y2,px1,py1,px2,py2;
fin>>x1>>y1>>x2>>y2>>px1>>py1>>px2>>py2;
x1+=1000;
x2+=1000;
y1+=1000;
y2+=1000;
px1+=1000;
px2+=1000;
py1+=1000;
py2+=1000;
int a1=(x2-x1)*(y2-y1);
if(x2<=px2&&x1>=px1&&y2<=py2&&y1>=py1){
fout<<0;
}
else if(x2<=px2&&x1>=px1){
if(py2>=y2){
fout<<0;
}
if((py2<=y1)|(py1>y1&&py2<y2) ){
fout<<a1;
}else{
int ma=max(py1,y1);
int mi=min(py2,y2);
fout<<((x2-x1)*(y2-y1))-((x2-x1)*(mi-ma));
cout<<((x2-x1)*(y2-y1))-((x2-x1)*(mi-ma)); /********************************************************/
}
}
else if(y2<=py2&&y1>=py1){
if(px2<=x1|px1>x1){
fout<<a1;
}else{
int ma=max(px1,x1);
fout<<((y2-y1)*(x2-x1))-((y2-y1)*(px2-ma));
}
}
else{
fout<<a1;
}
return 0;
}
解决方案
好的,所以发生的事情是我有一个 if that wold first fout<<0; 所以你必须非常小心
#include <bits/stdc++.h>
using namespace std;
int main() {
ifstream fin("billboard.in");
ofstream fout("billboard.out");
int x1,y1,x2,y2,px1,py1,px2,py2;
fin>>x1>>y1>>x2>>y2>>px1>>py1>>px2>>py2;
x1+=1000;
x2+=1000;
y1+=1000;
y2+=1000;
px1+=1000;
px2+=1000;
py1+=1000;
py2+=1000;
int a1=(x2-x1)*(y2-y1);
if(x2<=px2&&x1>=px1&&y2<=py2&&y1>=py1){
fout<<0;
}
else if(x2<=px2&&x1>=px1){
if((py2<=y1)|(py1>y1&&py2<y2) ){
fout<<a1;
}else{
int ma=max(py1,y1);
int mi=min(py2,y2);
fout<<((x2-x1)*(y2-y1))-((x2-x1)*(mi-ma));
}
}
else if(y2<=py2&&y1>=py1){
if(px2<=x1|px1>x1){
fout<<a1;
}else{
int ma=max(px1,x1);
fout<<((y2-y1)*(x2-x1))-((y2-y1)*(px2-ma));
}
}
else{
fout<<a1;
}
return 0;
}
推荐阅读
- carla - 卡拉刺激器上的 WinError 10061
- javascript - A2 服务器子文件夹中的 VueJs 部署问题
- flutter - Dart/Flutter linter 规则:索引地图的类型应该是地图的关键类型?
- java - 有没有办法在 Java 中设置默认参数?
- java - 如何在 Groovy 中创建动态长度的 Json 数组
- azure - “请求中指定的回复 URL 与为应用程序配置的回复 URL 不匹配”即使添加了 URL
- c++ - 双指针可以用作二维数组吗
- eventstoredb - EventStore.Client.Grpc.Streams 导致 LINQ 查询出现问题,例如 Where、FirstOrDefault
- java - 您好,我在 Eclipse 中用于 Selenium 测试的代码有问题
- asp.net-core-3.1 - 如何从 Utils 类的 GetValue 方法传递 Ilogger 引用