跳到正文

题解

题解:UVA12696 Cabin Baggage

Distorted_Fate_约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
获赞
4
题目
UVA12696

版本

  1. v1当前

题解:UVA12696 Cabin Baggage

本题要求判断行李箱是否合法。输入 aa,bb,cc,dd 四个浮点数,代表行李箱的长,宽,高,重量。满足以下要求则行李箱合法:

  • a≤56a \le 56,b≤45b \le 45,c≤25c \le 25 或者 a+b+c≤125a + b + c \le 125。

  • d≤7d \le 7。

多组数据,对于每组数据,如果行李箱合法输出一,否则输出零。在最后输出满足要求的行李箱数。

没什么好说的,按照题意模拟,注意变量定义的类型。

上代码!

C++
#include<bits/stdc++.h>
using namespace std;
int cnt,t;
int main(){
	cin>>t;
	while(t--){
		double length,width,depth,weight;
		cin>>length>>width>>depth>>weight;
		if((length<=56&&width<=45&&depth<=25 || length+width+depth<=125) && weight<=7){
			cout<<1<<endl;
			cnt++;
		}
		else cout<<0<<endl;
	}
	cout<<cnt<<endl;
	return 0;
}
原文