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;
- namespace _01.Largest_Common_End_1
- {
- class LargestCommonEnd
- {
- static void Main(string[] args)
- {
- string[] str1 = Console.ReadLine().Split().ToArray();
- string[] str2 = Console.ReadLine().Split().ToArray();
- //string[] str1 = { "hi", "php", "java", "csharp", "sql", "html", "css", "js" };
- //string[] str2 = { "hi", "php", "java", "js", "softuni", "nakov", "java", "learn" };
- //string[] str1 = { "hi", "php", "java", "xml", "csharp", "sql", "html", "css", "js" };
- //string[] str2 = { "nakov", "java", "sql", "html", "css", "js" };
- //Console.WriteLine(String.Join(" ", str1));
- //Console.WriteLine(string.Join(" ", str2));
- int len1 = str1.Length;
- int len2 = str2.Length;
- int j = 0;
- int countBegin = 0;
- int countEnd = 0;
- bool flagBegin = true;
- bool flagEnd = true;
- for (int i = 0; i < len1; i++)
- {
- // Checking BEGIN arr
- if (str1[i] == str2[j] && flagBegin)
- {
- countBegin++;
- }
- else
- {
- flagBegin = false;
- }
- // Checking END arr
- if (str1[len1 - 1 - i] == str2[len2 - 1 - j] && flagEnd)
- {
- countEnd++;
- }
- else
- {
- flagEnd = false;
- }
- j++;
- if (j == len2)
- {
- j = 0;
- }
- }
- if (countBegin >= countEnd)
- {
- Console.WriteLine(countBegin);
- }
- else
- {
- Console.WriteLine(countEnd);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement