BoBo买了一箱酸奶,里面有n盒未打开的酸奶,KiKi喜欢喝酸奶,第一时间发现了酸奶。KiKi每h分钟能喝光一盒酸奶,并且KiKi在喝光一盒酸奶之前不会喝另一个,那么经过m分钟后还有多少盒未打开的酸奶?
BoBo买了一箱酸奶,里面有n盒未打开的酸奶,KiKi喜欢喝酸奶,第一时间发现了酸奶。KiKi每h分钟能喝光一盒酸奶,并且KiKi在喝光一盒酸奶之前不会喝另一个,那么经过m分钟后还有多少盒未打开的酸奶?
多组输入,每组输入仅一行,包括n,h和m(均为整数)。输入数据保证m <= n * h。
针对每组输入,输出也仅一行,剩下的未打开的酸奶盒数。
8 5 16
4
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int h = scanner.nextInt(); int m = scanner.nextInt(); if(m % h == 0){ System.out.println(n - (m / h)); }else{ System.out.println(n - (m / h + 1)); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int h = sc.nextInt(); int m = sc.nextInt(); if (m % h == 0) { System.out.print(n - m / h); } else { System.out.print(n - m / h - 1); } } }
import java.util.*; public class Main { public static int getnums(int n,int h,int m){ while(m%h>0){ return n-m/h-1; } return n-m/h; } public static void main(String [] args) { Scanner input=new Scanner(System.in); int n=input.nextInt(); int h=input.nextInt(); int m=input.nextInt(); System.out.print(getnums(n,h,m)); } }
import java.util.Scanner; /** * * @Title KiKi和酸奶 * @Description <TODO> * BoBo买了一箱酸奶,里面有n盒未打开的酸奶,KiKi喜欢喝酸奶,第一时间发现了酸奶。 * KiKi每h分钟能喝光一盒酸奶,并且KiKi在喝光一盒酸奶之前不会喝另一个,那么经过m分钟后还有多少盒未打开的酸奶? * @author weijunfu<ijunfu @ qq.com> * @date 2022/03/14 23:14 * @version 1.0.0 * */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // 未打开的酸奶总盒数 int h = in.nextInt(); // 喝光一盒需要花费的时间 int m = in.nextInt(); // m分钟后,剩下的未打开的酸奶盒数 System.out.println(n - m/h - (m % h == 0 ? 0 : 1)); in.close(); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x1 = sc.nextInt(); //仍未打开的酸奶 int x2 = sc.nextInt(); //要多少分钟喝光一盒酸奶 int x3 = sc.nextInt(); //喝了多少分钟 //首先计算出经过了这么多分钟,喝了多少酸奶,1.刚好喝完一盒,2.一盒还没喝完 int n; n =(int)(x3 / x2); if(x3 % x2 == 0){ System.out.printf("%d",x1-n); } else{ System.out.printf("%d",x1-n-1); } } }
import java.util.*; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int h = scanner.nextInt(); int m = scanner.nextInt(); for (int i = 0; i < m ; i += h) { n--; } System.out.println(n); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int h = in.nextInt(); int m = in.nextInt(); int drink = (m/h); if (m%h!=0){ drink = drink+1; } System.out.println(n-drink); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = Integer.parseInt(sc.next()); int h = Integer.parseInt(sc.next()); int m = Integer.parseInt(sc.next()); if(m%h!=0){ n=n-(m/h+1); } else { n=n-(m/h); } System.out.println(n); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //总数 int n = scanner.nextInt(); //一瓶所用时间 int h = scanner.nextInt(); //经过时间 int m = scanner.nextInt(); //喝掉的酸奶总数=已经喝掉的(m/h)+喝了但没喝完的(m%h); int total = m % h > 0 ? m/h+1:m/h; int odd = n - total; System.out.println(odd); } }
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner input =new Scanner(System.in); while(input.hasNext())//多组输入 { int n=input.nextInt();//一共有n盒未打开的酸奶 int h=input.nextInt();//隔h分钟喝一盒酸奶 int m=input.nextInt();//m分钟后 System.out.println((int)(n-Math.ceil(((double)(m))/h)));//Math.ceil向上取整。例,1.21--2.00 } }}
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int q=0; while(scanner.hasNext()) { int n=scanner.nextInt();//n盒牛奶 int h=scanner.nextInt();//多长时间喝一个 int m=scanner.nextInt();//喝了这么长时间 if(m<h) { q=1; System.out.println(n-q); } else if (m%h==0) { q =m/h; System.out.println(n-q); } else { q =m/h; q=q+1; System.out.println(n-q); } } } }
首先判断分钟数能不能整除5,
如果能整除的话,
所喝的瓶数就是:分钟数/5,
否则就是:分钟数/5+1
剩下的=总数-所喝的
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNextInt()) { int n=sc.nextInt(); int h=sc.nextInt(); int m=sc.nextInt(); int f=(m%h==0?m/h:m/h+1); int result=n-f; System.out.println(result); } } }