FRom hackerrank

Alice wrote a sequence of words in CamelCase as a string of letters, , having the following properties:
  • It is a concatenation of one or more words consisting of English letters.
  • All letters in the first word are lowercase.
  • For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase.
Given , print the number of words in  on a new line.
For example, . There are  words in the string.

Solution in C# -

class Solution {
    static int camelcase(string s) {
        int count = 1;
        for(int i=0; i<s.Length; i++)
        {
            if(Char.IsUpper(s[i]))
            count++;
        }
        return count;
    }
    static void Main(string[] args) {
        TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
        string s = Console.ReadLine();
        int result = camelcase(s);
        textWriter.WriteLine(result);
        textWriter.Flush();
        textWriter.Close();
    }
}

Post a Comment

Previous Post Next Post