# CamelCase Hackerrank problem solution

### CamelCase Hackerrank

Alice wrote a sequence of words in CamelCase as a string of letters, s, 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 s, print the number of words in s on a new line.

Input Format

A single line containing string w.

Constraints

1<=|s|<=105
Output Format

Print the number of words in string s.

Sample Input

`saveChangesInTheEditor`

Sample Output

5
Explanation

String s contains five words:

save
Changes
In
The
Editor
Thus, we print 5 on a new line.

For Learnng  more visit:https: //coderinme.com/

##### Solution
``````#include<iostream>
using namespace std;
void solution() {
string str;
cin>>str;
int len = str.size(); //for claculating te length of the string
int ans = 1; //ans=1 because all letters in the first word are small
for(int i=0;i<len;i++)
{
if(str[i]>= 'A' && str[i]<= 'Z')   //checking uppercase letter
{
{
ans++;
}
}
}
cout<<ans<<endl;
}
int main()
{
solution();  //calling solution function
return 0;
}``````
``````(grep -o "[A-Z]";echo) | wc -l
``````
``````#include<stdio.h>
#include<string.h>
int main()
{
char str[100000];
scanf("%s",str);
int ans = 1,i;               //ans=1 because all letters in the first word are small
for(i = 0;str[i]!='\0'; i++)
{
if(str[i] >= 'A' && str[i] <= 'Z') {  //checking uppercase letter
ans++;
}
}
printf("%d",ans);
return 0;
}``````
``````import java.util.*;

public class Solution {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
scan.close();

// use a regex matching to split the string on capital letters
// the resulting array contains contiguous sections of lowercase letters
String[] words = s.split("[A-Z]");
// this works because the problem states that each word has at least 2 characters, and we know that the first character of each word is always capitalized.

System.out.println(words.length);
}
}
``````

You can also watch our video on our YouTube Channel “Coder InMe”

Note: All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin@coderinme.com

### hasectic

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi