Saturday, November 5, 2016

Hacker Rank - CamelCase

Problem:

Please find the problem here.

Solution: 

A capital letter indicates a word, the first word starts with lower case so 1 more word. The only case we need to be careful is that of empty string.

Code:

#include "stdafx.h"

// https://www.hackerrank.com/challenges/camelcase

#include <string>
#include <iostream>

using namespace std;

int HACKER_RANK_CAMEL_CASE()
{
    string s;
    cin >> s;
    int c = 0;
    if (s.length() > 0)
    {
        c++;
    }
    for (size_t i = 0; i < s.length(); i++)
    {
        if ('A' <= s[i] && s[i] <= 'Z')
        {
            c++;
        }
    }
    cout << c;
    return 0;
}

No comments :

Post a Comment