Advertisement
Guest User

code forces round 454 div. 2 question 1

a guest
Dec 24th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1.  
  2.  
  3.  
  4. public class ProblemA454 {
  5. public static void main(String agrs[]){
  6. Scanner sc = new Scanner(System.in);
  7. //puts all input into ints
  8. int papaBear = sc.nextInt();
  9. int mamaBear = sc.nextInt();
  10. int sonBear = sc.nextInt();
  11. int masha = sc.nextInt();
  12.  
  13. boolean mashaFits = false;
  14. // array of all possible car sizes of bear
  15. int[] a = new int[sonBear+1];
  16.  
  17. //puts all possible car sizes of bear inside array (size sonBear ... sonBear*2)
  18. for(int i = 0; i<a.length;i++){
  19. a[i] = sonBear + i;
  20.  
  21. }
  22.  
  23.  
  24. for(int j = 0; j<a.length;j++){
  25. //masha fits is boolean if masha fits into son bear car for any array)
  26. if(!mashaFits){
  27. if(masha <= a[j] && a[j] <= (masha * 2)){
  28.  
  29. System.out.println(papaBear);
  30. System.out.println(mamaBear);
  31. System.out.println(sonBear);
  32. //so for loop only runs once
  33. mashaFits = true;
  34. }
  35. }
  36. }
  37. //else print -1 as masha doesnt fit into any of son bears car values in array 1
  38. if(!mashaFits){
  39.  
  40. System.out.println("-1");
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement