-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camel Case 4 Hackerrank.cpp
59 lines (56 loc) · 1.4 KB
/
Camel Case 4 Hackerrank.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string _split(string s){
string out="";
for(int i=0;i<s.size();i++){
if(s[i]<97){
out+=" ";
out+=(s[i]+32);
}else{
out+=s[i];
}
}
return out;
}
string _combine(string s){
string out="";
for(int i=0;i<s.size();i++){
if(s[i]==' '){
i++;
s[i]-=32;
}
out+=s[i];
}
return out;
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */ string s;
while(getline(cin,s)){
s.erase(remove(s.begin(), s.end(), '\r'), s.end());
if(s[0]=='S'){
if(s[2]=='M'){
cout<<_split(s.substr(4,s.size()-4-2))<<endl;
}else if(s[2]=='V'){
cout<<_split(s.substr(4,s.size()-4))<<endl;
}else{
s[4]=s[4]+32;
cout<<_split(s.substr(4,s.size()-4))<<endl;
}
}else if(s[0]=='C'){
if(s[2]=='M'){
cout<<_combine(s.substr(4,s.size()-4))<<"()"<<endl;
}else if(s[2]=='V'){
cout<<_combine(s.substr(4,s.size()-4))<<endl;
}else{
s[4]-=32;
cout<<_combine(s.substr(4,s.size()-4))<<endl;
}
}
s="";
}
return 0;
}