Advertisement
Spocoman

03. Treasure Finder

Apr 17th, 2023
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace TreasureFinder
  7. {
  8.     class Program
  9.     {
  10.         static string SubStringFinder(string str, char start, char end)
  11.         {
  12.             int startIndex = str.IndexOf(start) + 1;
  13.             int endIndex = str.LastIndexOf(end) - startIndex;
  14.  
  15.             return str.Substring(startIndex, endIndex);
  16.         }
  17.         static void Main()
  18.         {
  19.             var key = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
  20.  
  21.             string command;
  22.  
  23.             while ((command = Console.ReadLine()) != "find")
  24.             {
  25.                 char[] message = command.ToCharArray();
  26.  
  27.                 for (int i = 0; i < command.Count(); i++)
  28.                 {
  29.                     message[i] = (char)(message[i] - key[i % key.Length]);
  30.                 }
  31.  
  32.                 string str = new string(message);
  33.                 string type = SubStringFinder(str, '&', '&');
  34.                 string coordinates = SubStringFinder(str, '<', '>');
  35.  
  36.                 Console.WriteLine($"Found {type} at {coordinates}");
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement