洛谷oj题单【入门2】分支结构-入门难度(Java)

来源:https://www.luogu.com.cn/training/101#problems

P5709 【深基2.习6】Apples Prologue / 苹果和虫子

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int m = sc.nextInt();int t = sc.nextInt();int s = sc.nextInt();if (t == 0)System.out.println(0);else {int apple = (int) Math.ceil(s / t);if (m <= apple)System.out.println(0);elseif(s % t != 0)System.out.println(m - apple - 1);elseSystem.out.println(m - apple);}}
}

P5710 【深基3.例2】数的性质

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x = sc.nextInt();//两种都符合System.out.print(((x % 2 == 0) && ((x > 4) && (x <= 12))) ? 1 : 0);System.out.printf(" ");//至少符合一种System.out.print(((x % 2 == 0) || ((x > 4) && (x <= 12))) ? 1 : 0);System.out.printf(" ");//只符合一种System.out.print(((x % 2 == 0) ^ ((x > 4) && (x <= 12))) ? 1 : 0);System.out.printf(" ");//都不符合System.out.print(((x % 2 != 0) && ((x <= 4) || (x > 12))) ? 1 : 0);}
}

P5711 【深基3.例3】闰年判断

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();if(n % 4 == 0 && n % 100 != 0 || n % 400 == 0)System.out.println(1);elseSystem.out.println(0);}
}

P5712[【深基3.例4】Apples

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();if(n == 0 || n == 1)System.out.println("Today, I ate "+n+" apple.");elseSystem.out.println("Today, I ate "+n+" apples.");}
}

P5713 【深基3.例5】洛谷团队系统

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();if(11 + 3 * n > 5 * n)System.out.println("Local");else System.out.println("Luogu");}
}

P5714 【深基3.例7】肥胖问题

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);double m = sc.nextDouble();double h = sc.nextDouble();double BMI = m / (h * h);if (BMI < 18.5)System.out.println("Underweight");else if (BMI >= 18.5 && BMI < 24)System.out.println("Normal");else {if (BMI - (int) BMI == 0)System.out.printf("%2.0f\n", BMI);//用题目中给的m=120/h=1.4计算出整数部分不会超过两位,所以占位符取2else if (BMI * 10 - (int) (BMI * 10) == 0)System.out.printf("%3.1f\n", BMI);//2位整数+1位小数点,所以占位符取3,保留小数点后1位,以下类推else if (BMI * 100 - (int) (BMI * 100) == 0)System.out.printf("%4.2f\n", BMI);else if (BMI * 1000 - (int) (BMI * 10000) == 0)System.out.printf("%5.3f\n", BMI);elseSystem.out.printf("%6.4f\n", BMI);//用题目中给的m=120/h=1.4计算出整数部分不会超过两位//所以6位有效数字最多就是2位整数+4位小数System.out.println("Overweight");}}
}

P5715 【深基3.例8】三位数排序

import java.util.Arrays;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int[] str = new int[3];for (int i = 0; i < 3; i++) {str[i] = sc.nextInt();}int a = str[0], b = str[1], c = str[2];Arrays.sort(str);for (int i=0;i<3;i++){System.out.print(str[i]+" ");}}
}

P5716 [【深基3.例9】月份天数

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int[] str = {0,31,28,31,30,31,30,31,31,30,31,30,31};//常规年份天数int y = sc.nextInt();//年int m = sc.nextInt();//月if(y % 4 == 0 && y % 100 != 0 || y % 400 == 0 )//判断是否为闰年,方便对2月进行判断str[2] = 29;System.out.printf("%d",str[m]);//方便输出}
}

P1085 [NOIP2004 普及组] 不高兴的津津

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a,b;int max = 0,res = 0;//分别为最大值,最终结果for (int i = 0; i < 7; i++) {a = sc.nextInt();b = sc.nextInt();if(a + b > 8 && a + b > max){max = a + b;res = i + 1;//i以0开头,所以应加1}}System.out.println(res);}
}

P1909 [NOIP2016 普及组] 买铅笔

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt(); //数量//三组数据int a1 = sc.nextInt();int a2 = sc.nextInt();int b1 = sc.nextInt();int b2 = sc.nextInt();int c1 = sc.nextInt();int c2 = sc.nextInt();//计算钱数int a = (int) (Math.ceil((double)n/(double)a1) * a2); //第一组int b = (int) (Math.ceil((double)n/(double)b1) * b2); //第二组int c = (int) (Math.ceil((double)n/(double)c1) * c2); //第三组//比较int min = a<b?a:b;min = min<c?min:c;//输出System.out.println(min);}
}

P1422 小玉家的电费

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();double sum = 0;if(n < 150){sum = n * 0.4463;}else if(n >= 150 && n < 400){sum = 150 * 0.4463 + (n -150) * 0.4663;} else if (n >= 401) {sum = 150 * 0.4463 + 250 * 0.4663 + (n - 400) * 0.5663;}System.out.printf("%.1f",sum);}
}

P1424 小鱼的航程(改进版)

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x = sc.nextInt();//从周x算起int n = sc.nextInt();//天数int sum = 0;for (int i = 0; i < n; i++) {//在循环中进行星期的判断switch (x){case 1:case 2:case 3:case 4:case 5:sum += 250;//工作日接着游泳case 6:x++;continue;//周六休息case 7:x = 1;continue;//周日重置为周一,并且休息不游泳}x++;//进入下一天}System.out.println(sum);}
}

P1888 三角函数

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 min = 0,max = 0;//求最小边min = a < b ? a : b;min = min < c ? min :c;//求斜边max = a > b ? a : b;max = max > c ? max :c;//辗转相除法求最大公因子int n = 0;for (int i = 1; i < min; i++) {if(max % i == 0 && min % i ==0){n = i;}}System.out.println(min/n+"/"+max/n );}
}

P1046 [NOIP2005 普及组] 陶陶摘苹果

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int[] arr = new int[10];for (int i = 0; i < arr.length; i++) {arr[i] = sc.nextInt();}int n = sc.nextInt();//总高度int num = 0;//个数for (int i = 0; i < arr.length; i++) {if(n+30 >= arr[i])num++;}System.out.println(num);}
}

P4414 [COCI2006-2007#2] ABC

import java.util.Scanner;
import java.util.Arrays;public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);int[] a = new int[3];a[0] = in.nextInt();a[1] = in.nextInt();a[2] = in.nextInt();Arrays.sort(a);//排序String str = in.next();char ch1 = str.charAt(0);//第一个字母char ch2 = str.charAt(1);//第二个字母char ch3 = str.charAt(2);//第三个字母System.out.println(a[ch1 - 'A'] + " " + a[ch2 - 'A'] + " " + a[ch3 - 'A']);}
}

洛谷oj题单【入门2】分支结构-入门难度(Java)相关推荐

  1. 洛谷oj题单【入门1】顺序结构-入门难度(Java)

    来源:https://www.luogu.com.cn/training/100#problems B2002 Hello,World! public class Main {public stati ...

  2. 洛谷日常刷题(洛谷官方题单 思路+详解)

    目录 前言 非官方题单的题 P1141 01迷宫 1-4 递推与递归 P1255 数楼梯 1002 [ NOIP 2002 普及组]过河卒 P1044 [NOIP2003 普及组] 栈 P1028 [ ...

  3. 洛谷-官方题单版【入门篇】

    文章目录 [入门1]顺序结构 P1000 超级玛丽游戏 *P5704 [深基2.例6]字母转换 P5705 [深基2.例7]数字反转 P1425 小鱼的游泳时间 P1421 小玉买文具 P3954 [ ...

  4. 【OJ】洛谷字符串题单题解锦集

    题单简介 题目解析 P5733[深基6.例1]自动修正 P1914 小书童--密码 P1125 笨小猴 P1957 口算练习题 P5015 标题统计 P5734[深基6.例6]文字处理软件 P1308 ...

  5. 【OJ】洛谷数组题单题解锦集

    题单简介 题目解析 P1428 小鱼比可爱 P1427 小鱼的数字游戏 P5727[深基5.例3]冰雹猜想 P1047 校门外的树 P5728[深基5.例5]旗鼓相当的对手 P5729[深基5.例7] ...

  6. 【OJ】洛谷排序题单题解锦集

    题单简介 题目解析 P1271[深基9.例1]选举学生会 P1177[模板]快速排序 P1923[深基9.例4]求第 k 小的数 P1059 明明的随机数 P1093 奖学金 P1781 宇宙总统 P ...

  7. 洛谷算法题单:模拟与高精度例题(上)

    一:模拟 想要利用计算机解决现实生活中的一些复杂的问题时,建立模型是解决问题的关键. 举个生活中常见的例子:我们拿到了某次数学考试的成绩单,现在需要知道谁考得最好.当然不能把成绩单对着电脑晃一晃,然后 ...

  8. 洛谷算法题单:模拟与高精度例题(下)

    接着上篇的例题. 1.洛谷P4924魔法少女小Scarlet 题目描述: Scarlet最近学会了一个数组魔法,她会在n∗n二维数组上将一个奇数阶方阵按照顺时针或者逆时针旋转90°, 首先,Scarl ...

  9. 洛谷刷题记录(python)【入门6】函数与结构体

    [入门6]函数与结构体https://www.luogu.com.cn/training/105#problems P5735 [深基7.例1]距离函数 import mathdef solve(a, ...

最新文章

  1. react native redux 梳理
  2. 准备踏入Android开发的道路
  3. s5pv210的中断源
  4. vue 组件需要注意的事项:
  5. kux播放器android,KUX转换器
  6. 9月7日冬瓜哥与你见面畅谈!
  7. 如何使用命令提示符轻松地将GPT转换为MBR而不会丢失数据?
  8. Linux内核网络:实现与理论--介绍
  9. ggplot2-数据关系型图表
  10. 4星+|《赋能:打造应对不确定性的敏捷团队》:海豹突击队学习伊拉克“基地”组织的组织形式并且最终战胜对方的故事...
  11. 修改 input checkbox(复选框) 选中的背景颜色 _@jie
  12. 去哪儿攻略app v3.9.2 官方iphone版
  13. ARFoundation从零开始3-创建ARFoundation项目
  14. java入门基础(四)
  15. 问题2:路径级别不清楚
  16. Apple Watch 关闭显示正在听的音乐
  17. 关于如何快速学好,学懂Linux内核。内含学习路线
  18. c# 获取两个时间之间的时间差
  19. photoshop快速抠图,几秒钟解决
  20. PTA(Basic Level) 1072:开学寄语(C语言实现)

热门文章

  1. Vue-05-v-model 双向绑定
  2. 艾司博讯:多多场景扣费?要怎么推广
  3. 创建员工表staff
  4. 华天动力协同办公系统V380中小企业版功能简介
  5. 改变自己错误的固有思想和行为(潜意识,如果不主动意识来改变,就会按照固有的潜意识来执行),只有一个办法,要么时刻想着画面,要么时刻语言提醒自己。以文字语言图片来驱动自己。
  6. 微信文本信息a标签无效
  7. 购买阿里云服务器和域名之后需要做的事
  8. adb命令以及云平台测试的报告
  9. 非常实用的PC软件,每一款都是神器!!
  10. 基础会计学习笔记12