Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class CountBeers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = "";
- ArrayList<String> list = new ArrayList<>();
- while (!input.equals("End")) {
- input = scanner.nextLine();
- if (input.equals("End")) {
- break;
- }
- list.add(input);
- }
- ArrayList<Integer> stacks = new ArrayList<>();
- ArrayList<Integer> beers = new ArrayList<>();
- int i = 0;
- while (i < list.size()) {
- if (list.get(i).contains("stacks")) {
- String[] parts = list.get(i).split(" ");
- stacks.add(Integer.parseInt(parts[0]));
- }
- i++;
- }
- i = 0;
- while (i < list.size()) {
- if (list.get(i).contains("beers")) {
- String[] parts = list.get(i).split(" ");
- beers.add(Integer.parseInt(parts[0]));
- }
- i++;
- }
- int b = 0;
- int s = 0;
- for (i = 0; i < beers.size(); i++) {
- b+=beers.get(i);
- }
- for (i = 0; i < stacks.size(); i++) {
- s+=stacks.get(i);
- }
- while (b >= 20) {
- b-=20;
- s++;
- }
- System.out.printf("%d stacks + %d beers", s, b);
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement