团体程序设计天梯赛-5分题集-Java

L1-001 Hello World (5分)

这道超级简单的题目没有任何输入。

你只需要在一行中输出著名短句“Hello World!”就可以了。

输入样例:

输出样例:
Hello World!

public class Main {
    
    
	public static void main(String[] args) {
    
    
		System.out.println("Hello World!");
	}
}

L1-004 计算摄氏温度 (5分)

给定一个华氏温度F,本题要求编写程序,计算对应的摄氏温度C。计算公式:C=5×(F−32)/9。题目保证输入与输出均在整型范围内。

输入格式:
输入在一行中给出一个华氏温度。

输出格式:
在一行中按照格式“Celsius = C”输出对应的摄氏温度C的整数值。

输入样例:
150
输出样例:
Celsius = 65

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int F, C;
		F = sc.nextInt();
		C = 5 * (F - 32) / 9;
		System.out.println("Celsius = "+C);
	}
}

L1-012 计算指数 (5分)

真的没骗你,这道才是简单题 —— 对任意给定的不超过 10 的正整数 n,要求你输出 2
​n
。不难吧?

输入格式:
输入在一行中给出一个不超过 10 的正整数 n。

输出格式:
在一行中按照格式 2^n = 计算结果 输出 2
​n
​​ 的值。

输入样例:
5
输出样例:
2^5 = 32
作者
陈越
单位
浙江大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB

import java.util.Scanner;
public class Main  {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int n, N = 1;
		n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
    
    
			N *= 2;//N = N * 2;
		}
		System.out.println("2^"+n+" = "+N);
	}
}

L1-014 简单题 (5分)

这次真的没骗你 —— 这道超级简单的题目没有任何输入。

你只需要在一行中输出事实:This is a simple problem. 就可以了。

输入样例:

输出样例:
This is a simple problem.

public class Main {
    
    
	public static void main(String[] args) {
    
    
		System.out.println("This is a simple problem.");
	}
}

L1-021 重要的话说三遍 (5分)

这道超级简单的题目没有任何输入。

你只需要把这句很重要的话 —— “I’m gonna WIN!”——连续输出三遍就可以了。

注意每遍占一行,除了每行的回车不能有任何多余字符。

输入样例:

输出样例:
I’m gonna WIN!
I’m gonna WIN!
I’m gonna WIN!

public class Main {
    
    
	public static void main(String[] args) {
    
    
		for(int i=0;i<3;i++) {
    
    
			System.out.println("I'm gonna WIN!");
		}
	}
}

L1-024 后天 (5分)

如果今天是星期三,后天就是星期五;如果今天是星期六,后天就是星期一。我们用数字1到7对应星期一到星期日。给定某一天,请你输出那天的“后天”是星期几。

输入格式:
输入第一行给出一个正整数D(1 ≤ D ≤ 7),代表星期里的某一天。

输出格式:
在一行中输出D天的后天是星期几。

输入样例:
3
输出样例:
5

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int[] days = new int[]{
    
    3,4,5,6,7,1,2};
		int i = sc.nextInt();
		System.out.println(days[i-1]);
	}
}

L1-026 I Love GPLT (5分)

这道超级简单的题目没有任何输入。

你只需要把这句很重要的话 —— “I Love GPLT”——竖着输出就可以了。

所谓“竖着输出”,是指每个字符占一行(包括空格),即每行只能有1个字符和回车。

输入样例:

输出样例:
I

L
o
v
e

G
P
L
T
注意:输出的两个空行中各有一个空格。

public class Main {
    
    
	public static void main(String[] args) {
    
    
		String str = "I Love GPLT";
		for(int i=0;i<str.length();i++) {
    
    
			System.out.println(str.charAt(i));
		}
	}
}

L1-029 是不是太胖了 (5分)

据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。已知市斤的数值是公斤数值的两倍。现给定某人身高,请你计算其标准体重应该是多少?(顺便也悄悄给自己算一下吧……)

输入格式:
输入第一行给出一个正整数H(100 < H ≤ 300),为某人身高。

输出格式:
在一行中输出对应的标准体重,单位为市斤,保留小数点后1位。

输入样例:
169
输出样例:
124.2
作者
陈越
单位
浙江大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		double n;
		int h = sc.nextInt();
		if (h <= 300 && h >= 100) {
    
    
			n = (h - 100) * 0.9 * 2;
			System.out.printf("%.1f", n);
		} else {
    
    
			System.out.println("input error !");
		}
	}
}

L1-036 A乘以B (5分)

看我没骗你吧 —— 这是一道你可以在 10 秒内完成的题:给定两个绝对值不超过 100 的整数 A 和 B,输出 A 乘以 B 的值。

输入格式:
输入在第一行给出两个整数 A 和 B(−100≤A,B≤100),数字间以空格分隔。

输出格式:
在一行中输出 A 乘以 B 的值。

输入样例:
-8 13
输出样例:
-104

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		int a, b, c;
		a = sc.nextInt();
		b = sc.nextInt();
		if (a <= 100 && a >= -100 && b <= 100 && b >= -100) {
    
    
			c = a * b;
			System.out.println(c);
		} else {
    
    
			System.out.println("input error !");
		}
	}
}

L1-038 新世界 (5分)

这道超级简单的题目没有任何输入。

你只需要在第一行中输出程序员钦定名言“Hello World”,并且在第二行中输出更新版的“Hello New World”就可以了。

输入样例:

输出样例:
Hello World
Hello New World

public class Main {
    
    
	public static void main(String[] args) {
    
    
		String str1 = "Hello World";
		String str2 ;
		str2 = str1.substring(0, 5)+" New "+str1.substring(6);
		System.out.println(str1);
		System.out.println(str2);
	}
}

L1-042 日期格式化 (5分)

世界上不同国家有不同的写日期的习惯。比如美国人习惯写成“月-日-年”,而中国人习惯写成“年-月-日”。下面请你写个程序,自动把读入的美国格式的日期改写成中国习惯的日期。

输入格式:
输入在一行中按照“mm-dd-yyyy”的格式给出月、日、年。题目保证给出的日期是1900年元旦至今合法的日期。

输出格式:
在一行中按照“yyyy-mm-dd”的格式给出年、月、日。

输入样例:
03-15-2017
输出样例:
2017-03-15

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String year = s.substring(6,10);
		String day = s.substring(3,5);
		String mouth = s.substring(0,2);
		System.out.println(year+"-"+mouth+"-"+day);
	}
}

L1-045 宇宙无敌大招呼 (5分)

据说所有程序员学习的第一个程序都是在屏幕上输出一句“Hello World”,跟这个世界打个招呼。作为天梯赛中的程序员,你写的程序得高级一点,要能跟任意指定的星球打招呼。

输入格式:
输入在第一行给出一个星球的名字S,是一个由不超过7个英文字母组成的单词,以回车结束。

输出格式:
在一行中输出Hello S,跟输入的S星球打个招呼。

输入样例:
Mars
输出样例:
Hello Mars

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		String s  = sc.next();
		System.out.println("Hello "+s);	
    }
}

L1-051 打折 (5分)

去商场淘打折商品时,计算打折以后的价钱是件颇费脑子的事情。例如原价 ¥988,标明打 7 折,则折扣价应该是 ¥988 x 70% = ¥691.60。本题就请你写个程序替客户计算折扣价。

输入格式:
输入在一行中给出商品的原价(不超过1万元的正整数)和折扣(为[1, 9]区间内的整数),其间以空格分隔。

输出格式:
在一行中输出商品的折扣价,保留小数点后 2 位。

输入样例:
988 7
输出样例:
691.60

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner sc = new Scanner(System.in);
		double a,b,c;
		a = sc.nextDouble();
		c = sc.nextInt();
		b = a*(c/10);
		System.out.printf("%.2f",b);
	}
}

L1-052 2018我们要赢 (5分)

2018年天梯赛的注册邀请码是“2018wmyy”,意思就是“2018我们要赢”。本题就请你用汉语拼音输出这句话。

输入格式:
本题没有输入。

输出格式:
在第一行中输出:“2018”;第二行中输出:“wo3 men2 yao4 ying2 !”。

输入样例:

输出样例:
2018
wo3 men2 yao4 ying2 !

public class Main {
    
    
	public static void main(String[] args) {
    
    
		System.out.println("2018");
		System.out.println("wo3 men2 yao4 ying2 !");
	}
}

L1-057 PTA使我精神焕发 (5分)

在这里插入图片描述

以上是湖北经济学院同学的大作。本题就请你用汉语拼音输出这句话。

输入格式:
本题没有输入。

输出格式:
在一行中按照样例输出,以惊叹号结尾。

输入样例:

输出样例:
PTA shi3 wo3 jing1 shen2 huan4 fa1 !
作者
陈越
单位
浙江大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB

public class Main {
    
    
	public static void main(String[] args) {
    
    
		System.out.println("PTA shi3 wo3 jing1 shen2 huan4 fa1 !");
	}
}

L1-060 心理阴影面积 (5分)

在这里插入图片描述

这是一幅心理阴影面积图。我们都以为自己可以匀速前进(图中蓝色直线),而拖延症晚期的我们往往执行的是最后时刻的疯狂赶工(图中的红色折线)。由红、蓝线围出的面积,就是我们在做作业时的心理阴影面积。

现给出红色拐点的坐标 (x,y),要求你算出这个心理阴影面积。

输入格式:
输入在一行中给出 2 个不超过 100 的正整数 x 和 y,并且保证有 x>y。这里假设横、纵坐标的最大值(即截止日和最终完成度)都是 100。

输出格式:
在一行中输出心理阴影面积。

友情提醒:三角形的面积 = 底边长 x 高 / 2;矩形面积 = 底边长 x 高。嫑想得太复杂,这是一道 5 分考减法的题……

输入样例:
90 10
输出样例:
4000

import java.util.Scanner;
public class Main {
    
    
	public static void main(String[] args) {
    
    
		Scanner input = new Scanner(System.in);
		int x, y, array = 0;
		x = input.nextInt();
		y = input.nextInt();
		if (x > y && x <= 100 && x >= 0 && y <= 100 && y >= 0) {
    
    
			array = 50 * (x - y);
			System.out.println(array);
		} else {
    
    
			System.out.println("input error !");
		}
	}

猜你喜欢

转载自blog.csdn.net/Bennettgxd/article/details/109516571