https://vjudge.net/contest/274223#problem/G
题解:第一行包括赛题数目,使用了while循环条件来控制输入的赛题;
第二行与第三行通过数组来存储字节数,并且比较出最小字节数。
以下是AC代码:
#include<iostream>
using namespace std;
int main()
{
int n, a, b, i = 0; //n表示题目数量,i表示第几题
int c[20], d[500]; //建立数组存储字节数
int min1, min2;
cin >> n;
if(n>0&&n<=13)
while (n != 0)
{
i++, n--;
cin >> a >> b;
if (a >= 2)
for (int j = 0; j < a; j++)
cin >> c[j];
for (int j = 0; j < b; j++)
cin >> d[j];
min2 = 0;
for (int j = 1; j < b; j++)
if (d[j] < d[min2])
min2 = j;
A:min1 = 0; //先记数组第一个数为最小值
for (int j = 1; j < a; j++) //往后逐个比较
if (c[j] < c[min1])
min1 = j; //记住该数组中最小数的下标
if (b != 0)
{
cout << "Problem" <<" "<< 1000 + i << ":" << endl;
cout << "Shortest judge solution: " << c[min1] << " bytes." << endl;
cout << "Shortest team solution: " << d[min2] << " bytes." << endl;
}
else {
cout << "Problem" <<" "<< 1000 + i << ":" << endl;
cout << "Shortest judge solution: " << c[min1] << " bytes." << endl;
cout << "Shortest team solution: " << "N/A bytes." << endl;
}
}
}