Advertisement
Guest User

TreasureHunt

a guest
Nov 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. package TresureHunter;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.  
  10.     static class Treasure{
  11.         String name;
  12.         String coordinates;
  13.  
  14.         public void setName(String name) {
  15.             this.name = name;
  16.         }
  17.  
  18.         public void setCoordinates(String coordinates) {
  19.             this.coordinates = coordinates;
  20.         }
  21.  
  22.         public String getName() {
  23.             return name;
  24.         }
  25.  
  26.         public String getCoordinates() {
  27.             return coordinates;
  28.         }
  29.     }
  30.  
  31.     public static void main(String[] args) {
  32.         Scanner scanner = new Scanner(System.in);
  33.         List<Treasure> treasureList=new ArrayList<>();
  34.         int[] keys= Arrays
  35.                 .stream(scanner.nextLine().split("\\s+"))
  36.                 .mapToInt(Integer::parseInt)
  37.                 .toArray();
  38.  
  39.         String input=scanner.nextLine();
  40.         while (!"find".equals(input)){
  41.             char[] currentLine=input.toCharArray();
  42.             for (int i = 0; i <currentLine.length ; i++) {
  43.  
  44.                 for (int j = 0; j <keys.length; j++) {
  45.                     currentLine[i]-=keys[j];
  46.                     if (i<currentLine.length-1 && j<keys.length-1) {
  47.                         i++;
  48.                     }
  49.                 }
  50.             }
  51.             String decrypted=new String(currentLine);
  52.             String treasureType=decrypted.substring(decrypted.indexOf('&')+1,decrypted.lastIndexOf('&'));
  53.             String coordinates=decrypted.substring(decrypted.indexOf('<')+1,decrypted.length()-1);
  54.             Treasure treasure=new Treasure();
  55.             treasure.setName(treasureType);
  56.             treasure.setCoordinates(coordinates);
  57.             treasureList.add(treasure);
  58.             input=scanner.nextLine();
  59.         }
  60.  
  61.         for (Treasure treasure : treasureList) {
  62.             System.out.printf("Found %s at %s%n",treasure.getName(),treasure.getCoordinates());
  63.         }
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement