Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TresureHunter;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- static class Treasure{
- String name;
- String coordinates;
- public void setName(String name) {
- this.name = name;
- }
- public void setCoordinates(String coordinates) {
- this.coordinates = coordinates;
- }
- public String getName() {
- return name;
- }
- public String getCoordinates() {
- return coordinates;
- }
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Treasure> treasureList=new ArrayList<>();
- int[] keys= Arrays
- .stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .toArray();
- String input=scanner.nextLine();
- while (!"find".equals(input)){
- char[] currentLine=input.toCharArray();
- for (int i = 0; i <currentLine.length ; i++) {
- for (int j = 0; j <keys.length; j++) {
- currentLine[i]-=keys[j];
- if (i<currentLine.length-1 && j<keys.length-1) {
- i++;
- }
- }
- }
- String decrypted=new String(currentLine);
- String treasureType=decrypted.substring(decrypted.indexOf('&')+1,decrypted.lastIndexOf('&'));
- String coordinates=decrypted.substring(decrypted.indexOf('<')+1,decrypted.length()-1);
- Treasure treasure=new Treasure();
- treasure.setName(treasureType);
- treasure.setCoordinates(coordinates);
- treasureList.add(treasure);
- input=scanner.nextLine();
- }
- for (Treasure treasure : treasureList) {
- System.out.printf("Found %s at %s%n",treasure.getName(),treasure.getCoordinates());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement