|
发表于 2020-5-14 18:30:01
|
显示全部楼层
运行于Linux的代码:
#include <iostream>
using namespace std;
int main()
{
int a,b;
int X_min,X_max;
int Y_min,Y_max;
int Z;
int X,Y;
int doonce=0;
cout<<"Input a,b"<<endl;
cin >> a >> b;
cout<<"Input X_min,X_max"<<endl;
cin >> X_min >> X_max;
cout<<"Input Y_min,Y_max"<<endl;
cin >> Y_min >> Y_max;
for (X=X_min;X<=X_max;X++)
{
for (Y=Y_min;Y<=Y_max;Y++)
{
if (doonce==0)
{
Z = a*X - b*Y;
doonce = 1;
}
if (Z < (a*X - b*Y))
{
Z = a*X - b*Y;
}
}
}
cout<<"The min of a*X - b*Y = "<<Z<<endl;
return 0;
}
|
|