There is a sequence of words in CamelCase as a string of letters,s, having the following properties:
1.It is a concatenation of one or more words consisting of English letters.
2.All letters in the first word are lowercase.
3.For each of the subsequent words, the first letter is uppercase, and the rest of the letters are lowercase.
Givens, determine the number of words in s.
Example:
Input: s="saveChangesInTheEditor"
Output: 5
Approach
Java
public class CamelCase {public static void main(String[] args) {String s = "saveChangesInTheEditor";System.out.println(camelcase(s));}private static int camelcase(String s) {int l, count = 0;l = s.length();for (int i = 0; i < l; i++) {if (s.charAt(i) >= 65 && s.charAt(i) <= 90)count++;}return count + 1;}}
C++
#include <bits/stdc++.h>using namespace std;int camelcase(string s){long long l, count = 0;l = s.size();for (long long i = 0; i < l; i++){if (s[i] >= 65 && s[i] <= 90)count++;}return count + 1;}int main(){string s = "saveChangesInTheEditor";cout << camelcase(s);return 0;}
No comments:
Post a Comment