Saturday, 16 June 2018

Monk Teaches Palindrome

Monk introduces the concept of palindrome saying,"A palindrome is a sequence of characters which reads the same backward or forward."
Now, since he loves things to be binary, he asks you to find whether the given string is palindrome or not. If a given string is palindrome, you need to state that it is even palindrome (palindrome with even length) or odd palindrome (palindrome with odd length).
Input:
The first line consists of T, denoting the number of test cases.
Next follow T lines, each line consisting of a string of lowercase English alphabets.
Output:
For each string , you need to find whether it is palindrome or not.
If it is not a palindrome, print NO.
If it is a palindrome, print YES followed by a space; then print EVEN it is an even palindrome else print ODD.
Output for each string should be in a separate line.
See the sample output for clarification.
Constraints:
1T50
1length of string105
SAMPLE INPUT
 
3
abc
abba
aba
SAMPLE OUTPUT
 
NO
YES EVEN
YES ODD
Explanation
The first string is not a palindrome.
The second and third strings are palindromes of even and odd lengths respectively.






using System;

public class Program
{
    public static void Main(string[] args)
    {
    int tc= int.Parse(Console.ReadLine());
    
    while(tc>0)
    {
        string str= Console.ReadLine();
        int l= str.Length;
        int lp = l/2-1;
        bool isP=true;
        string strR="NO";
        for(int i=0;i<=lp;i++)
        {
            if(!(str.Substring(i,1)==str.Substring(l-1-i,1)))
            {
                isP=false;
                break;
            }
            
        }
        if(isP)
        {
          if(l%2==0)
          {
              strR="YES EVEN";
          }
          else
          {
              strR="YES ODD";
          }
        }
        
        Console.WriteLine(strR);
        tc--;
    }
}
}

Thursday, 14 June 2018

Little Monk and Good String

Little monk loves good string. Good String is a string that only contains vowels (a,e,i,o,u). Now, his teacher gave him a string S. Little monk is wondering what is the length of the longest good string which is a substring of S.
Note: Strings contains only lower case English Alphabets.
Input:
First line contains a string S(1|S|105), where S denotes the length of the string.
Output:
Print an integer denoting the length of the longest good substring, that is substring consists of only vowels.
SAMPLE INPUT
abcaac
SAMPLE OUTPUT
2
Explanation
Longest Good String which is a substring of S is aa so the answer is 2.



using System;
using System.IO;
public class Program
{
    public static void Main(string[] args)
    {
        byte[] inputBuffer = new byte[9024];
            Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
            Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
        String str= Console.ReadLine();
        string str1=string.Empty;
            string str2= string.Empty;
        
       // if(IsStringInLowerCase(str))
       // {
            
            int totalCount=0;
            int count=0;
            foreach(char c in str)
            {
                if(isCharVowel(c))
                {
                    count++;
                    if(count>totalCount)
                    {
                        totalCount=count;
                    }
                   // str1=str1 + c.ToString();
                   // if(str1.Length>=str2.Length)
                    //{
                        //str2=str1;
                   // }
                     
                }
                else
                {
                     //if (str1.Length >= str2.Length)
                       // {
                          //  str2 = str1;
                        //}
                   // str1=string.Empty;
                   count=0;
                }
            }
       // }
        
     Console.WriteLine(totalCount);
        
    }
    
    public static bool IsStringInLowerCase(string str)
    {
        bool isLower= true;
        foreach(char c in str)
        {
            int aC = (int)c;
            
            if(!(aC>='a' && aC<='z'))
            {
                isLower=false;
                
            }
            
        }
        return isLower;
    }
    
    public static bool isCharVowel(char c)
    {
        if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
        {
            
            return true;
        }
        else
        return false;
    }
    
}

Wednesday, 6 June 2018

Find out biggest substring from given string having all distinct character

 using System;  
 namespace AlgoApp  
 {  
   class Program  
   {  
     static void Main(string[] args)  
     {  
       Console.WriteLine("Press any key to continue or n to discontinue");  
       //while (Console.ReadLine() != "n")  
       //{  
       Console.WriteLine("input string!");  
       String inputStr = Console.ReadLine();  
       String str = inputStr.Substring(0, 1);  
       String str2 = string.Empty;  
       String strFinal = string.Empty;  
       if (inputStr.Length > 1)  
       {  
         //abcd  
         //abbccde  
         //aaaa  
         //abcade  
         //abbcde  
         //abbccdefffefghi  
         int count = 0;  
       foreach (char c in inputStr)  
       {  
         for (int i = count; i < inputStr.Length-1; i++)  
         {  
           if (!IsDuplicate(str, inputStr.Substring(i + 1, 1)))  
           {  
             str = str + inputStr.Substring(i + 1, 1);  
           }  
           else  
           {  
               if (strFinal.Length < str.Length)  
                 strFinal = str;  
             str = string.Empty;  
             break;  
           }  
         }  
         if (strFinal.Length < str.Length)  
         {  
           strFinal = str;  
         }  
         count = count + 1;  
       }  
         Console.WriteLine("substring having distinct character= " + strFinal);  
       }  
         else if (inputStr.Length == 1)  
         {  
           Console.WriteLine("substring having distinct character= " + inputStr);  
         }  
         else  
         {  
           Console.WriteLine("input string should be in lowercase alphabat letter");  
         }  
         Console.WriteLine("Press any key to continue or n to discontinue");  
       // }  
       Console.ReadLine();  
     }  
     public static bool IsDuplicate(string str,string c)  
     {  
       bool isDuplicateChar = false;  
       for(int i=0;i<str.Length;i++)  
       {  
         if(str.Substring(i,1)==c)  
         {  
           isDuplicateChar = true;  
         }  
       }  
       return isDuplicateChar;  
     }  
   }  
 }