-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathCamel_Case.cpp
44 lines (42 loc) · 1.28 KB
/
Camel_Case.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*Name : Atul Kumar
Github username : atul1510
Repositary name : Algorithms
*/
/*Problem Description
Program to convert text sentence in CamelCase format .
Examples:
1] INPUT: "this is camel case"
OUTPUT "thisIsCamelCase"
2] INPUT: "Hi Atul here"
OUTPUT: "hiAtulHere"
Example Explanation */
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
int Testcase;
cout << "Enter no of Testcases: ";
cin >> Testcase;
cout << endl;
cin.ignore(); // Clear the input buffer
while (Testcase--) {
string str;
cout << "Enter a sentence: ";
getline(cin, str);
bool flag = false;
string camelCaseString = "";
for (int i = 0; i < str.length(); i++) {
if (i == 0) camelCaseString += tolower(str[i]); //Converts to lowercase
else if (str[i] == ' ') flag = true; // Check for spaces in the sentence
else if (flag && str[i] != ' ') {
camelCaseString += toupper(str[i]); //Converts to uppercase
flag = false;
}
else camelCaseString += tolower(str[i]); //Converts to lowercase
}
cout << "Original: " << str << endl;
cout << "Camel Case: " << camelCaseString << endl;
}
return 0;
}