String Strange Pair

Two strings can be pair if meets blow criteria
• The first string’s first letter = second string’s last letter.
• The first string’s last letter = second string’s first letter.
Write a program to check if two string can be pair

For example

Input:
groups
sounding

output:
Strange pair of string

Solution:


using System;

namespace StrangeString
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Enter a string");
            var firstStr = Console.ReadLine();
            Console.WriteLine("Enter a string");
            var secondStr = Console.ReadLine();

            if (string.IsNullOrEmpty(firstStr) || string.IsNullOrEmpty(secondStr))
            {
                Console.WriteLine("Invalid strings");
                return;
            }

            if (firstStr[0] == secondStr[secondStr.Length - 1] &&
                firstStr[firstStr.Length - 1] == secondStr[0])
                Console.WriteLine("Strange pair of string");
            else
                Console.WriteLine("Not strange pair of string");

            Console.ReadLine();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *