Advertisement
MeliDragon

TitleSearch100Points

Nov 24th, 2022
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace next
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string title = Console.ReadLine();
  11.             // input word
  12.             int lines = int.Parse(Console.ReadLine());
  13.             // number of words
  14.             int index = 0;
  15.             for (int i = 0; i < lines; i++)
  16.             {
  17.                 string word = Console.ReadLine().ToLower();
  18.                 //the sequence to search in the "title"
  19.                 string temp = title;
  20.                 //string to manipulate while keeping "title", so if the sequence is not found  
  21.                 // the original string is unchanged
  22.                 int count = 0;
  23.                 for (int j = 0; j < word.Length; j++)
  24.                 {
  25.                     if (temp.IndexOf(word[j], index) > -1)
  26.                     {
  27.                         index = temp.IndexOf(word[j], index);
  28.                         string firstPart = temp.Substring(0, index);
  29.                         string secondPart = temp.Substring(index + 1, temp.Length - index - 1);
  30.                         temp = firstPart + secondPart;
  31.                         count++;
  32.                     }
  33.                     else
  34.                     {
  35.                         break;
  36.                     }
  37.                 }
  38.  
  39.                 if (count == word.Length)
  40.                 {
  41.                     Console.WriteLine(temp);
  42.                     title = temp;
  43.                     index = 0;
  44.                 }
  45.                 else
  46.                 {
  47.                     Console.WriteLine("No such title found!");
  48.                     index = 0;
  49.                 }
  50.  
  51.             }
  52.  
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement