Advertisement
MeliDragon

TitleSearch

Nov 20th, 2022 (edited)
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 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 = -1;
  15.             for (int i = 0; i < lines; i++)
  16.             {
  17.                 string word = Console.ReadLine().ToLower();
  18.                 //the sequence to surch 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.                 if (word.Length>title.Length)
  23.                 {
  24.                     Console.WriteLine("No such title found!");
  25.                     index = 2;
  26.                     continue;
  27.                 }
  28.  
  29.                 for (int j = 0; j < word.Length; j++)
  30.                 {
  31.                     index = temp.IndexOf(word[j].ToString());
  32.                     if (index > -1)
  33.                     {
  34.                         temp = temp.Remove(index, 1);
  35.                         index = -1;
  36.                         if (j == word.Length-1)
  37.                         {
  38.                             index = 1;
  39.                         }
  40.                     }
  41.                 }
  42.  
  43.                 if (index == 1)
  44.                 {
  45.                     Console.WriteLine(temp);
  46.                     title = temp;
  47.                 }
  48.                 else if(index == -1)
  49.                 {
  50.                     Console.WriteLine("No such title found!");
  51.                 }
  52.  
  53.             }
  54.  
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement