There is 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, determine the number of words in s.
Example
s = oneTwoThree
There are 3 words in the string: ‘one’, ‘Two’, ‘Three’.
Function Description
Complete the camelcase function in the editor below.
camelcase has the following parameter(s):
- string s: the string to analyze
Returns
- int: the number of words in s
Input Format
A single line containing string s.
Constraints
- 1<=length of s<=10^5
Sample Input
saveChangesInTheEditor
Sample Output
5
Explanation
String s contains five words:
- save
- Changes
- In
- The
- Editor
TABLE OF CONTENTS
CamelCase HackerRank Solution in C
#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> int main(){ char* s = (char *)malloc(10240 * sizeof(char)); scanf("%s",s); int coun=0,i; for(i=0;i<strlen(s);i++) { if(s[i]>=65 && s[i]<=90){coun++;} } printf("%d\n",coun+1); return 0; }
CamelCase HackerRank Solution in C++
#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <string> #include <bitset> #include <cstdio> #include <limits> #include <vector> #include <climits> #include <cstring> #include <cstdlib> #include <fstream> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; int main(){ string s; cin >> s; int t=1; for (int i=0;i<s.length();i++) if (isupper(s[i])) t++; cout<<t<<endl; return 0; }
CamelCase HackerRank Solution in Java
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); int count = 1; for(int i = 0; i<s.length(); i++){ char c = s.charAt(i); if(c>='A' && c<='Z') count++; } System.out.println(count); } }
CamelCase HackerRank Solution in Python
#!/bin/python import sys s = raw_input().strip() count=0 for i in s: if i.upper()==i: count+=1 print count+1
CamelCase HackerRank Solution in C#
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { string line = Console.ReadLine(); int ans = 0; foreach (var c in line) { if (c < 'a') ans++; } Console.WriteLine(ans+1); } }
Attempt CamelCase HackerRank Challenge
Link – https://www.hackerrank.com/challenges/camelcase
Next HackerRank Challenge Solution
Link – https://exploringbits.com/insertion-sort-part-1-hackerrank-solution/
Aayush Kumar Gupta is the founder and creator of ExploringBits, a website dedicated to providing useful content for people passionate about Engineering and Technology. Aayush has completed his Bachelor of Technology (Computer Science & Engineering) from 2018-2022. From July 2022, Aayush has been working as a full-time Devops Engineer.