Little monk loves good string. Good String is a string that only contains vowels . 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, , 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.
Note: Strings contains only lower case English Alphabets.
Input:
First line contains a string S, , 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
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;
}
}
Longest Good String which is a substring of S is so the answer is 2.
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;
}
}
No comments:
Post a Comment