Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1
- {
- using System;
- public class StartUp
- {
- public static void Main()
- {
- char[] splitSymbols = new[] { ' ' };
- string[] firstWords = SplitString(Console.ReadLine(), splitSymbols);
- string[] secondWords = SplitString(Console.ReadLine(), splitSymbols);
- int leftCompare = CompareStringArrays(firstWords, secondWords);
- Reverse(firstWords);
- Reverse(secondWords);
- int rightCompare = CompareStringArrays(firstWords, secondWords);
- Console.WriteLine(Math.Max(leftCompare, rightCompare));
- }
- public static void Reverse(string[] arrayToReverse)
- {
- for (int currentIndex = 0; currentIndex < arrayToReverse.Length / 2; currentIndex++)
- {
- int lastIndex = arrayToReverse.Length - 1 - currentIndex;
- string holder = arrayToReverse[lastIndex];
- arrayToReverse[lastIndex] = arrayToReverse[currentIndex];
- arrayToReverse[currentIndex] = holder;
- }
- }
- public static int CompareStringArrays(string[] firstArray, string[] secondArray)
- {
- int counter = 0;
- int smallerLength = Math.Min(firstArray.Length, secondArray.Length);
- for (int currentElement = 0; currentElement < smallerLength; currentElement++)
- {
- string firstElement = firstArray[currentElement];
- string secondElement = secondArray[currentElement];
- if (firstElement.Equals(secondElement))
- {
- counter++;
- }
- else
- {
- break;
- }
- }
- return counter;
- }
- public static string[] SplitString(string stringToSplit, char[] splitSymbols)
- {
- return stringToSplit.Split(splitSymbols, StringSplitOptions.RemoveEmptyEntries);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement