当前位置:   article > 正文

【洛谷】【入门1】顺序结构(Java8)_目描述用 * 构造一个对角线长 55 个字符,倾斜放置的菱形。

目描述用 * 构造一个对角线长 55 个字符,倾斜放置的菱形。

1.B2002 Hello,World!

  1. public class Main {
  2. public static void main(String[] args) {
  3. System.out.println("Hello,World!");
  4. }
  5. }

2.B2025 输出字符菱形

  1. public class Main {
  2. public static void main(String[] args) {
  3. System.out.println(" * ");
  4. System.out.println(" *** ");
  5. System.out.println("*****");
  6. System.out.println(" *** ");
  7. System.out.println(" * ");
  8. }
  9. }

3.P1000 超级玛丽游戏

  1. public class Main {
  2. public static void main(String []args){
  3. System.out.println(
  4. " ********\n" +
  5. " ************\n" +
  6. " ####....#.\n" +
  7. " #..###.....##....\n" +
  8. " ###.......###### ### ###\n" +
  9. " ........... #...# #...#\n" +
  10. " ##*####### #.#.# #.#.#\n" +
  11. " ####*******###### #.#.# #.#.#\n" +
  12. " ...#***.****.*###.... #...# #...#\n" +
  13. " ....**********##..... ### ###\n" +
  14. " ....**** *****....\n" +
  15. " #### ####\n" +
  16. " ###### ######\n" +
  17. "##############################################################\n" +
  18. "#...#......#.##...#......#.##...#......#.##------------------#\n" +
  19. "###########################################------------------#\n" +
  20. "#..#....#....##..#....#....##..#....#....#####################\n" +
  21. "########################################## #----------#\n" +
  22. "#.....#......##.....#......##.....#......# #----------#\n" +
  23. "########################################## #----------#\n" +
  24. "#.#..#....#..##.#..#....#..##.#..#....#..# #----------#\n" +
  25. "########################################## ############");
  26. }
  27. }

4.P1001 A+B Problem

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

5.B2005 字符三角形

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. String a = sc.next();
  6. System.out.printf(" " + " " + "%s\n", a);
  7. System.out.printf(" " + "%s%s%s\n", a, a, a);
  8. System.out.printf("%s%s%s%s%s\n", a, a, a, a, a);
  9. }
  10. }

6.P5703 【深基2.例5】苹果采购

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

7.P5704 【深基2.例6】字母转换

  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args){
  4. Scanner cin = new Scanner(System.in);
  5. char a = cin.next().charAt(0);
  6. System.out.println((char)(a + ('A' - 'a')));
  7. }
  8. }

8.P5705 【深基2.例7】数字反转

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. String s = sc.next();
  6. for (int i = s.length() - 1; i >= 0 ; i--) {
  7. System.out.print(s.charAt(i));
  8. }
  9. }
  10. }

9.P5706 【深基2.例8】再分肥宅水

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc=new Scanner(System.in);
  5. double a=sc.nextDouble();
  6. int b=sc.nextInt();
  7. System.out.printf("%.3f\n", a/b);
  8. System.out.println(b*2);
  9. }
  10. }

10.P5708 【深基2.习2】三角形面积

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc=new Scanner (System.in);
  5. double a=sc.nextDouble();
  6. double b=sc.nextDouble();
  7. double c=sc.nextDouble();
  8. double p=(a+b+c)/2;
  9. double s=Math.sqrt(p*(p-a)*(p-b)*(p-c));
  10. System.out.printf("%.1f",s);
  11. }
  12. }

11.P5707 【深基2.例12】上学迟到

  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. int s = sc.nextInt();
  6. int v = sc.nextInt();
  7. int h = 0;
  8. int m = 0;
  9. int t = (int)Math.ceil(s/(v+0.0))+10;
  10. int time = 8*60;
  11. int tmp = time - t;
  12. if(tmp<0) {
  13. tmp += 24*60;
  14. }
  15. h = tmp/60;
  16. m = tmp-h*60;
  17. if(h<10) {
  18. System.out.print(0+""+h);
  19. }else {
  20. System.out.print(h);
  21. }
  22. System.out.print(":");
  23. if(m<10) {
  24. System.out.print(0+""+m);
  25. }else {
  26. System.out.print(m);
  27. }
  28. }
  29. }

12.B2029 大象喝水

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. int h = sc.nextInt();
  6. int r = sc.nextInt();
  7. double pi = 3.14;
  8. double v = pi * r * r * h / 1000;
  9. int result = (int) (20 / v) + 1;
  10. System.out.println(result);
  11. }
  12. }

13.P1425 小鱼的游泳时间

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Scanner sc = new Scanner(System.in);
  5. int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
  6. if(d<b) {
  7. System.out.println(c-a-1 +" "+ (d+60-b));
  8. }else {
  9. System.out.println(c-a +" "+ (d-b));
  10. }
  11. }
  12. }

14.P1421 小玉买文具

  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args){
  4. Scanner sc = new Scanner(System.in);
  5. int a =sc.nextInt(),b = sc.nextInt();
  6. System.out.println((a*10+b)/19);
  7. }
  8. }

15.P3954 [NOIP2017 普及组] 成绩

  1. import java.util.Scanner;
  2. public class Main {
  3. public static void main(String []args) {
  4. Scanner sc = new Scanner(System.in);
  5. int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
  6. System.out.println((int)(a*0.2 + b*0.3 + c*0.5));
  7. }
  8. }

结语:“难道向上攀爬的那条路,不是比站在顶峰更让人热血澎湃吗?”--贺炜

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/877763
推荐阅读
相关标签
  

闽ICP备14008679号