Advertisement
Guest User

sdf

a guest
Nov 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4.  
  5. namespace _3_Threasure_Finder
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] key = Console.ReadLine()
  12.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.  
  16.             while (true)
  17.             {
  18.                string text = Console.ReadLine();
  19.  
  20.                 if (text == "find")
  21.                 {
  22.                     break;
  23.                 }
  24.  
  25.                 int keyCounter = 0;
  26.                 string newSequence = string.Empty;
  27.  
  28.                 for (int i = 0; i < text.Length; i++)
  29.                 {
  30.                     int charNum = text[i] - key[keyCounter];
  31.  
  32.                     newSequence += (char)charNum;
  33.                     keyCounter++;
  34.  
  35.                     if (keyCounter == key.Length)
  36.                     {
  37.                         keyCounter = 0;
  38.                     }
  39.                 }
  40.  
  41.                 int startTypeIndex = newSequence.IndexOf("&") + 1;
  42.                 int endTypeIndex = newSequence.LastIndexOf("&");
  43.                 string treasureType = newSequence
  44.                     .Substring(startTypeIndex, endTypeIndex - startTypeIndex);
  45.  
  46.                 int startCordinationsIndex = newSequence.IndexOf("<") + 1;
  47.                 int endCordinationsIndex = newSequence.LastIndexOf(">");
  48.                 string treasureCordinates = newSequence
  49.                     .Substring(startCordinationsIndex, endCordinationsIndex - startCordinationsIndex);
  50.  
  51.                 Console.WriteLine($"Found {treasureType} at {treasureCordinates}");
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement