7-7 12-24小时制
分数 15
作者 翁恺
单位 浙江大学
编写一个程序,要求用户输入24小时制的时间,然后显示12小时制的时间。

输入格式:
输入在一行中给出带有中间的:符号(半角的冒号)的24小时制的时间,如12:34表示1234分。当小时或分钟数小于10时,均没有前导的零,如5:6表示5点零6分。

提示:在scanf的格式字符串中加入:,让scanf来处理这个冒号。

输出格式:
在一行中输出这个时间对应的12小时制的时间,数字部分格式与输入的相同,然后跟上空格,再跟上表示上午的字符串AM或表示下午的字符串PM。如5:6 PM表示下午5点零6分。注意,在英文的习惯中,中午12点被认为是下午,所以24小时制的12:00就是12小时制的12:0 PM;而0点被认为是第二天的时间,所以是0:0 AM。

输入样例:
21:11
输出样例:
9:11 PM
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// 读取24小时制的时间
String inputTime = scanner.nextLine();
scanner.close();

// 使用 split 方法分割时间字符串
String[] timeParts = inputTime.split(":");
int hour = Integer.parseInt(timeParts[0]); // 小时部分
int minute = Integer.parseInt(timeParts[1]); // 分钟部分

// 确定AM或PM以及调整小时
String period;
if (hour >= 12) {
period = "PM";
if (hour > 12) {
hour -= 12; // 将13-23时转换为1-11时
} else if (hour == 0) {
hour = 12; // 处理24小时制的0点,即12:xx AM
}
} else {
period = "AM";
if (hour == 0) {
hour = 0; // 处理24小时制的0点,即12:xx AM
}
}

// 格式化输出
System.out.printf("%d:%d %s\n", hour, minute, period);
}
}

7-8 超速判断
分数 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
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int v = sc.nextInt();
if(v <= 60){
System.out.println("Speed: "+v+" - "+"OK");
}else{
System.out.println("Speed: "+v+" - "+"Speeding");
}
}
}
7-9 用天平找小球
分数 10
作者 C课程组
单位 浙江大学
三个球A、B、C,大小形状相同且其中有一个球与其他球重量不同。要求找出这个不一样的球。

输入格式:
输入在一行中给出3个正整数,顺序对应球A、B、C的重量。

输出格式:
在一行中输出唯一的那个不一样的球。

输入样例:
1 1 2
输出样例:
C
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// 读取输入
int weightA = scanner.nextInt();
int weightB = scanner.nextInt();
int weightC = scanner.nextInt();
scanner.close();

// 找出不一样的球
if (weightA != weightB && weightA != weightC) {
System.out.println("A");
} else if (weightB != weightA && weightB != weightC) {
System.out.println("B");
} else if (weightC != weightA && weightC != weightB) {
System.out.println("C");
}
}
}


7-10 计算工资
分数 15
作者 沈睿
单位 浙江大学
某公司员工的工资计算方法如下:一周内工作时间不超过40小时,按正常工作时间计酬;超出40小时的工作时间部分,按正常工作时间报酬的1.5倍计酬。员工按进公司时间分为新职工和老职工,进公司不少于5年的员工为老职工,5年以下的为新职工。新职工的正常工资为30元/小时,老职工的正常工资为50元/小时。请按该计酬方式计算员工的工资。

输入格式:
输入在一行中给出2个正整数,分别为某员工入职年数和周工作时间,其间以空格分隔。

输出格式:
在一行输出该员工的周薪,精确到小数点后2位。

输入样例1
5 40
输出样例1
2000.00
输入样例2
3 50
输出样例2
1650.00


import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int age = sc.nextInt();
int hour = sc.nextInt();
sc.close();
double money=0;
if(age>=5){
if(hour >= 40){
money=50*40*1.0+1.5*(hour-40)*1.0*50;
}
else{
money = 50 * hour*1.0;
}
}else{
if(hour >= 40){
money = 30*40*1.0+1.5*(hour-40)*1.0*30;
}else{
money = 30 * hour*1.0;
}
}
System.out.printf("%.2f",money);
}


}

7-11 分段计算居民水费
分数 10
作者 沈睿
单位 浙江大学
为鼓励居民节约用水,自来水公司采取按用水量阶梯式计价的办法,居民应交水费y(元)与月用水量x(吨)相关:当x不超过15吨时,y=4x/3;超过后,y=2.5x−17.5。请编写程序实现水费的计算。

输入格式:
输入在一行中给出非负实数x。

输出格式:
在一行输出应交的水费,精确到小数点后2位。

输入样例1
12
输出样例1
16.00
输入样例2
16
输出样例2
22.50


import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
sc.close();
double y = 0;
if(x<=15){
y = 1.0*4*x/3;
}else{
y = 2.5*x-17.5;
}
System.out.printf("%.2f",y);
}
}


6-1 简单输出整数
分数 10
作者 陈越
单位 浙江大学
本题要求实现一个函数,对给定的正整数N,打印从1到N的全部正整数。

函数接口定义:
void PrintN ( int N );
其中N是用户传入的参数。该函数必须将从1到N的全部正整数顺序打印出来,每个数字占1行。

裁判测试程序样例:
#include <stdio.h>

void PrintN ( int N );

int main ()
{
int N;

scanf("%d", &N);
PrintN( N );

return 0;
}

/* 你的代码将被嵌在这里 */
输入样例:
3
输出样例:
1
2
3

void PrintN ( int N ){
for(int i = 1;i<=N;i++){
printf("%d\n",i);
}
}