第二期训练第一题

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;
			}
		}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值