Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P_20160228_CollectResources {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String resources = scanner.nextLine();
- int rows = scanner.nextInt();
- scanner.nextLine();
- int result = 0;
- for (int i = 0; i < rows; i++) {
- String[] temp = new String(resources).split(" ");
- String[] steps = scanner.nextLine().split(" ");
- int start = Integer.parseInt(steps[0]);
- int step = Integer.parseInt(steps[1]);
- int tempResult = collectResources(temp, start, step);
- if (result < tempResult) {
- result = tempResult;
- }
- }
- System.out.println(result);
- }
- private static int collectResources(String[] resources, int start, int step) {
- String[] res = resources[start].split("[^a-zA-Z]+");
- String[] qty = resources[start].split("[^0-9]+");
- int sumOfRsources = 0;
- while (res.length != 0) {
- if (start >= resources.length) {
- start -= resources.length;
- if (start >= resources.length) {
- break;
- }
- }
- res = resources[start].split("[^a-z]+");
- qty = resources[start].split("[^0-9]+");
- if (res.length == 0) {
- break;
- } else if (res[0].equals("stone") || res[0].equals("gold")
- || res[0].equals("wood") || res[0].equals("food")) {
- sumOfRsources += qty.length > 0 ? Integer.parseInt(qty[1]) : 1;
- resources[start] = "*";
- } else {
- resources[start] = "*";
- }
- start += step;
- }
- return sumOfRsources;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment