//这题的大意是:给定你一个五位数,但头和尾的数缺失,需要你找出头和尾的两个数(注意:头的数不为0)
//如果有多种情况的,就输出其最大的那个数!
#include "iostream"
#include "algorithm"
using namespace std;
struct Info
{
int firstnum;
int endnum;
int price;
}info[100];
bool cmp(Info a, Info b)
{
return a.price > b.price;
}
int main()
{
int testcase, i, j, k, x, y, z, n, temp;
double ans;
bool flag;
cin >> testcase;
while (testcase--)
{
cin >> n >> x >> y >> z;
k = 0;
ans = 0.0;
flag = false;
for (i = 0; i < 100; i++)//再次犯下了这些低级错误,使用之前没有初始化!WA了两次!
{
info[i].firstnum = 0;
info[i].endnum = 0;
info[i].price = 0;
}
for (i = 1; i <= 9; i++)
for (j = 0; j <= 9; j++)
{
temp = i * 10000 + x * 1000 + y * 100 + z * 10 + j;
ans = temp / (n * (1.0));
if (ans == int (ans))
{
info[k].firstnum = i;
info[k].endnum = j;
info[k].price = (int)ans;
k++;
flag = true;
}
}
sort(info, info+100, cmp);
if (flag)
cout << info[0].firstnum << " " << info[0].endnum << " " << info[0].price << endl;
else
cout << "0" << endl;
}
}
zoj 2679 Old Bill
最新推荐文章于 2020-02-23 11:24:17 发布