洛谷oj题单【入门1】顺序结构-入门难度(Java)
2023-03-31 10:39:59 时间
洛谷oj题单【入门1】顺序结构-入门难度(Java)
来源:https://www.luogu.com.cn/training/100#problems
B2002 Hello,World!
public class Main {
public static void main(String[] args){
System.out.println("Hello,World!");
}
}
B2025 输出字符菱形
public class Main {
public static void main(String[] args){
System.out.println(" * ");
System.out.println(" *** ");
System.out.println("*****");
System.out.println(" *** ");
System.out.println(" * ");
}
}
P1001 A+B Problem
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = a+b;
System.out.println(c);
}
}
B2005 字符三角形
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(" "+s+" ");
System.out.println(" "+s+s+s+" ");
System.out.println(s+s+s+s+s);
}
}
B5703 【深基2.例5】苹果采购
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 现在需要采购一些苹果,每名同学都可以分到固定数量的苹果,并且已经知道了同学的数量,请问需要采购多少个苹果?/
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int apple = a * b;
System.out.println(apple);
}
}
P5704 【深基2.例6】字母转换
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 输入一个小写字母,输出其对应的大写字母。例如输入 q[回车] 时,会输出 Q。/
Scanner sc = new Scanner(System.in);
char a = sc.next().charAt(0);
char b = (char) (a - 32);
System.out.println(b);
}
}
P5705 【深基2.例7】数字反转
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num = sc.nextDouble();
int n = (int)(num * 10);
double temp = 0;
while(n != 0){ //这里的n必须为int类型,若为double或float,n可无限趋近于0
temp = n % 10 + temp * 10;
n /= 10;
}
System.out.printf("%.3f",temp/1000);
}
}
P5706 【深基2.例8】再分肥宅水
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
float t = sc.nextFloat();
int n = sc.nextInt();
float a = t/n;
int b = 2*n;
System.out.printf("%.3f",a);
System.out.println();
System.out.println(b);
}
}
P5708 【深基2.习2】三角形面积
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
double p = (a + b + c) / 2.0;
Math.sqrt(p*(p-a)*(p-b)*(p-c));
System.out.printf("%.1f",Math.sqrt(p*(p-a)*(p-b)*(p-c)));
}
}
B2029 大象喝水
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int r = sc.nextInt();
int a = 20 * 1000;
double b = 3.14 * r * r * h ;
int n = (int)Math.ceil(a/b);
System.out.println(n);
}
}
P1425 小鱼的游泳时间
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int x = c - a;
int y = d - b;
if(y < 0){
x--;
y = d + 60 - b;
}
System.out.print(x + " ");
System.out.print(y);
}
}
P1421 小玉买文具
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int x = a * 10 + b;
int y = 1 * 10 + 9;
int res = (int)Math.floor(x/y);
System.out.println(res);
}
}
P3954 [NOIP2017 普及组] 成绩
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int res = (int) (a * 0.2 + b * 0.3 + c * 0.5);
System.out.println(res);
}
}
相关文章
- Notepad++ 中 Analyse Plugin插件
- 干货 | 耗时缩短2/3,Taro编译打包优化实践
- 面试中经常问的安全测试问题
- JetBrains 官宣:“下一代 IDE 「Fleet」 登场!” 对标 VS Code?
- 俄罗斯开发者或因制裁无法访问开源代码?Github CEO发文否认
- DDD为什么能火起来?和微服务有啥关系?
- 赶超谷歌!世界超大时间晶体刷新破纪录,量子计算机再创奇迹
- 一文掌握Conda软件安装:虚拟环境、软件通道、加速solving、跨服务器迁移
- 分子结构模拟工具UCSF Chimera的安装及基本操作
- TCL高速增长启示录:科技巨头要走远唯有“苦练内功”
- ensp 模拟 calico 跨网段 bgp 网络
- T资讯:谷歌:捐赠 1500 万美元用于乌克兰救助;比亚迪公布车辆面部识别系统;粉笔科技拟赴港上市;百度第四季度营收 331 亿元,同比增长 9%
- 纸壳CMS v3.5升级.Net 6
- 手把手带你B站少量弹幕爬取并生成词云
- 根据 PDF 模板产生各种电子订单
- Netty 多线程模型
- 我的4年学习心得:AI 应该是一个整体!
- RESTful 访问权限管理实现思路,采用路径匹配神器之 AntPathMatcher
- 拉驴子出来溜溜,VFPBS实战做一个查询页面
- 高手从来不用什么框架,摘叶即可飞花,但他们从来没有说BS入门该么做