Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TitleSearch
- {
- class Program
- {
- static void Main(string[] args)
- {
- string word = Console.ReadLine();
- int count = int.Parse(Console.ReadLine());
- string[] phrases = new string[count];
- for (int i = 0; i < count; i++)
- {
- phrases[i] = Console.ReadLine();
- }
- for (int i = 0; i < phrases.Length; i++)
- {
- if (exist(phrases[i], word))
- {
- modify(ref word, phrases[i]);
- Console.WriteLine(word);
- }
- else Console.WriteLine("No such title found!");
- }
- }
- public static bool exist(string phrase, string word)
- {
- char[] phraseChar = phrase.ToCharArray();
- for (int i = 0; i < phraseChar.Length; i++)
- {
- if (!word.Contains(phraseChar[i]))
- {
- return false;
- }
- }
- return true;
- }
- public static string modify(ref string word, string phrase)
- {
- char[] wordChar = word.ToCharArray();
- char[] phraseChar = phrase.ToCharArray();
- StringBuilder sb = new StringBuilder();
- List<int> indexes = new List<int>();
- for (int i = 0; i < phraseChar.Length; i++)
- {
- int index = word.IndexOf(phraseChar[i]);
- if (indexes.Contains(index))
- {
- index = word.IndexOf(phraseChar[i], word.IndexOf(phraseChar[i]) + 1);
- }
- wordChar[index] = ' ';
- indexes.Add(index);
- }
- for (int i = 0; i < wordChar.Length; i++)
- {
- if (wordChar[i] != ' ')
- {
- sb.Append(wordChar[i]);
- }
- }
- word = sb.ToString();
- return word;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment