1 条题解
-
0
第十三题:
题目描述:
2578:Keep on Truckin'
题目链接:
P2578——Keep on Truckin'——柒行(www.oj7.cn)
题目来源:
WSouth Central USA 2003
总时间限制:
1000ms
内存限制:
65536kB
描述
Boudreaux and Thibodeaux are on the road again . . .
"Boudreaux, we have to get this shipment of mudbugs to Baton Rouge by tonight!"
"Don't worry, Thibodeaux, I already checked ahead. There are three underpasses and our 18-wheeler will fit through all of them, so just keep that motor running!"
"We're not going to make it, I say!"
So, which is it: will there be a very messy accident on Interstate 10, or is Thibodeaux just letting the sound of his own wheels drive him crazy?
输入
Input to this problem will consist of a single data set. The data set will be formatted according to the following description.
The data set will consist of a single line containing 3 numbers, separated by single spaces. Each number represents the height of a single underpass in inches. Each number will be between 0 and 300 inclusive.
输出
There will be exactly one line of output. This line will be:
NO CRASH
if the height of the 18-wheeler is less than the height of each of the underpasses, or: CRASH X
otherwise, where X is the height of the first underpass in the data set that the 18-wheeler is unable to go under (which means its height is less than or equal to the height of the 18-wheeler). The height of the 18-wheeler is 168 inches.
样例输入
180 160 170
样例输出
CRASH 160
中文题面:
布德罗和蒂博多再次上路了……
“布德罗,我们必须在今晚之前把这一批小龙虾送到巴吞鲁日!”
“别担心,蒂博多,我已经提前查看过了。有三个地下通道,我们的十八轮大卡车都能通过,所以只要让引擎继续运转就行!”
“我们到不了的,我说!”
那么,问题来了:在第10州际公路上会发生一场非常混乱的事故,还是蒂博多只是被他自己车轮的声音逼疯了? 输入 这个问题的输入将由一个单一的数据集合成。数据集的格式将按照以下描述进行格式化。
数据集将由一行组成,包含个数字,以单个空格分隔。每个数字代表一个地下通道的高度(以英寸为单位)。每个数字将在之间,包括。 输出 输出将只有一行。 如果十八轮大卡车的高度低于每个地下通道的高度, 则输出为:
NO CRASH
否则,输出为:
CRASH X
其中X是数据集里第一个十八轮大卡车无法通过的地下通道的高度(这意味着它的高度小于或等于十八轮大卡车的高度)。
十八轮大卡车的高度是英寸。
180 160 170
样例输出
CRASH 160
算法标签
if语句
解题思路
读取输入,检查第一个地下通道的高度是否小于或等于 ,如果是,则输出 "" 和该高度。 如果第一个地下通道的高度大于 ,则继续检查第二个地下通道的高度。以此类推,如果所有地下通道的高度都大于 ,则输出 ""。
实现步骤
1.声明三个整数变量 存储地下通道的高度。 2.定义一个常量 表示十八轮大卡车的高度。 3.使用 语句判断每个地下通道的高度是否小于或等于 。
C++实现
#include <iostream> #include <stdio.h> using namespace std; int main(){ int h1,h2,h3; cin>>h1>>h2>>h3; int limit=168; if(limit>=h1){ printf("CRASH %d",h1); return 0; }else if(limit>=h2) { printf("CRASH %d",h2); return 0; }else if(limit>=h3){ printf("CRASH %d",h3); return 0; }else{ printf("NO CRASH"); } return 0; }
- 1
信息
- ID
- 1579
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 4
- 已通过
- 1
- 上传者