Advertisement
kalinkata

CountBeers

Dec 16th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class CountBeers {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String input = "";
  10.  
  11. ArrayList<String> list = new ArrayList<>();
  12.  
  13. while (!input.equals("End")) {
  14. input = scanner.nextLine();
  15.  
  16. if (input.equals("End")) {
  17. break;
  18. }
  19.  
  20. list.add(input);
  21. }
  22.  
  23. ArrayList<Integer> stacks = new ArrayList<>();
  24. ArrayList<Integer> beers = new ArrayList<>();
  25.  
  26. int i = 0;
  27.  
  28. while (i < list.size()) {
  29. if (list.get(i).contains("stacks")) {
  30. String[] parts = list.get(i).split(" ");
  31. stacks.add(Integer.parseInt(parts[0]));
  32. }
  33. i++;
  34. }
  35.  
  36. i = 0;
  37.  
  38. while (i < list.size()) {
  39. if (list.get(i).contains("beers")) {
  40. String[] parts = list.get(i).split(" ");
  41. beers.add(Integer.parseInt(parts[0]));
  42. }
  43. i++;
  44. }
  45.  
  46. int b = 0;
  47. int s = 0;
  48.  
  49. for (i = 0; i < beers.size(); i++) {
  50. b+=beers.get(i);
  51. }
  52.  
  53. for (i = 0; i < stacks.size(); i++) {
  54. s+=stacks.get(i);
  55. }
  56.  
  57. while (b >= 20) {
  58. b-=20;
  59. s++;
  60. }
  61.  
  62. System.out.printf("%d stacks + %d beers", s, b);
  63. scanner.close();
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement