Advertisement
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;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- { // my solution, below other solutions commented:
- string input = Console.ReadLine();
- string pattern = Console.ReadLine();
- while (true)
- {
- //1Sample2ExamJun2016 3FootballStandings
- StringBuilder sb = new StringBuilder(input);
- int indexFirst = input.IndexOf(pattern);
- int indexLast = input.LastIndexOf(pattern);
- if (indexFirst > -1 && indexLast > -1 && pattern != String.Empty)
- {
- sb.Remove(indexFirst, pattern.Length);
- input = sb.ToString();
- sb.Remove(input.LastIndexOf(pattern), pattern.Length); //indexLast-pattern.Length
- input = sb.ToString();
- //Console.WriteLine(input);
- Console.WriteLine("Shaked it.");
- sb = new StringBuilder(pattern);
- if (pattern.Length > 0)
- {
- int indexToRemove = pattern.Length / 2;
- //Console.WriteLine(indexToRemove);
- sb.Remove(indexToRemove, 1);
- pattern = sb.ToString();
- //Console.WriteLine(pattern);
- }
- }
- else
- {
- Console.WriteLine("No shake.");
- Console.WriteLine(input);
- break;
- }
- }
- }
- }
- // Надолу още 2 решения:
- // Най-оптималната програма:
- //string input = Console.ReadLine(); /// Не слагай ToLower
- //string pattern = Console.ReadLine(); /// Не слагай ToLower
- // while (true)
- // {
- // int indexFirst = input.IndexOf(pattern);
- //int indexLast = input.LastIndexOf(pattern);
- // if(indexFirst!=indexLast)
- // {
- // input = input.Remove(indexFirst, pattern.Length);
- // input = input.Remove(input.LastIndexOf(pattern), pattern.Length); //indexLast-pattern.Length
- // Console.WriteLine("Shaked it.");
- // pattern = pattern.Remove(pattern.Length / 2, 1);
- // if (pattern == "")
- // {
- // Console.WriteLine("No shake.");
- // Console.WriteLine(input);
- // break;
- // }
- // }
- // else
- // {
- // Console.WriteLine("No shake.");
- // Console.WriteLine(input);
- // break;
- // }
- // Treto reshenie:
- // StringBuilder optimized:
- //string input = Console.ReadLine();
- //string pattern = Console.ReadLine();
- //while (true)
- //{
- // int indexFirst = input.IndexOf(pattern);
- // int indexLast = input.LastIndexOf(pattern);
- // if (indexFirst != indexLast)
- // {
- // StringBuilder sb = new StringBuilder(input);
- // sb.Remove(indexFirst, pattern.Length);
- // input = sb.ToString();
- // sb.Remove(input.LastIndexOf(pattern), pattern.Length); //indexLast-pattern.Length
- // input = sb.ToString();
- // Console.WriteLine("Shaked it.");
- // sb = new StringBuilder(pattern);
- // int indexToRemove = pattern.Length / 2;
- // sb.Remove(indexToRemove, 1);
- // pattern = sb.ToString();
- // if (pattern == "")
- // {
- // Console.WriteLine("No shake.");
- // Console.WriteLine(input);
- // break;
- // }
- // }
- // else
- // {
- // Console.WriteLine("No shake.");
- // Console.WriteLine(input);
- // break;
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement