7-21 超速判断 (10 分)
模拟交通警察的雷达测速仪。输入汽车速度,如果速度超出60 mph,则显示“Speeding”,否则显示“OK”。
输入格式:
输入在一行中给出1个不超过500的非负整数,即雷达测到的车速。
输出格式:
在一行中输出测速仪显示结果,格式为:Speed: V - S,其中V是车速,S或者是Speeding、或者是OK。
输入样例1:
40
输出样例1:
Speed: 40 - OK
输入样例2:
75
输出样例2:
Speed: 75 - Speeding
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
if (a<=60)
{
printf("Speed: %d - OK",a);
}
else
{
printf("Speed: %d - Speeding",a);
}
return 0;
}
7-22 用天平找小球 (10 分)
三个球A、B、C,大小形状相同且其中有一个球与其他球重量不同。要求找出这个不一样的球。
输入格式:
输入在一行中给出3个正整数,顺序对应球A、B、C的重量。
输出格式:
在一行中输出唯一的那个不一样的球。
输入样例:
1 1 2
输出样例:
C
#include<stdio.h>
int main()
{
int A, B, C;
scanf("%d %d %d",&A, &B, &C);
if (A == B)
{
printf("C");
}
else if (A == C)
{
printf("B");
}
else if (B == C<