Write a C# Sharp program to check whether a given string is an “isograms” or not. Return True or False

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to check whether a given string is an “isograms” or not. Return True or False.

From Wikipedia,
A heterogram (from hetero-, meaning 'different', + -gram, meaning 'written') is a word, phrase, or sentence in which no letter of the alphabet occurs more than once. The terms isogram and nonpattern word have also been used to mean the same thing.

Expected Output :

Original string: Python
Check the said string is an 'isograms' or not! True

Original string: JavaScript
Check the said string is an 'isograms' or not! False

Original string: PHP
Check the said string is an 'isograms' or not! False

Original string: C#
Check the said string is an 'isograms' or not! True

الأجوبة

using System;
using System.Linq;
using System.Collections.Generic;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = "Python";
            Console.WriteLine("Original string: "+ str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
            str1 = "JavaScript";
            Console.WriteLine("\nOriginal string: " + str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
            str1 = "PHP";
            Console.WriteLine("\nOriginal string: " + str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
            str1 = "C#";
            Console.WriteLine("\nOriginal string: " + str1);
            Console.WriteLine("Check the said string is an 'isograms' or not! " + test(str1));
        }
        public static bool test(string str1)
        {
            int str_len = str1.Length;
            return str1.ToLower().Distinct().Count() == str_len;
        }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...