Advertisement
elena1234

TreasureFinder* -howToLooping

Nov 15th, 2020
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Linq;
  4.  
  5. namespace TreasureFinder
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             string text = string.Empty;
  13.             string type = string.Empty;
  14.             string coordinates = string.Empty;
  15.             while((text=Console.ReadLine())!="find")
  16.             {
  17.                 int maxLength = Math.Max(numbers.Length, text.Length);// found maxLength
  18.                 StringBuilder sb = new StringBuilder(maxLength);
  19.                 for (int i = 0; i < maxLength; i++)
  20.                 {
  21.                     sb.Append((char)(text[i] - numbers[i % numbers.Length]));// NB! how to looping
  22.                 }
  23.  
  24.                 int startIndexType = sb.ToString().IndexOf('&') + 1;
  25.                 int endIndexType = sb.ToString().IndexOf('&', startIndexType + 1);
  26.                 int typeLength = endIndexType - startIndexType;
  27.                 type = sb.ToString().Substring(startIndexType, typeLength);
  28.  
  29.                 int startIndexCoordinates = sb.ToString().IndexOf('<') + 1;
  30.                 int endIndexCoordinates = sb.ToString().IndexOf('>');
  31.                 int coordinatesLength = endIndexCoordinates - startIndexCoordinates;
  32.                 coordinates = sb.ToString().Substring(startIndexCoordinates, coordinatesLength);
  33.                 Console.WriteLine($"Found {type} at {coordinates}");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement