-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3613.cpp
54 lines (48 loc) · 1.09 KB
/
3613.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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string str;
bool flag = false;
void JavaToC() {
while (str.find('_') != string::npos) {
int pos = str.find('_');
str.erase(pos,1);
str[pos] -= ('a' - 'A');
}
}
void CToJava() {
for (int i = 0; i < str.size(); i++) {
if (str[i] < 'a') {
str.insert(i, "_");
str[i+1] += ('a' - 'A');
i++;
}
}
}
int main(){
cin >> str;
if (str[0] < 'a' || str[0]=='_' || str[str.size()-1]=='_') flag = true;
if (flag == false) {
for (int i = 0; i < str.size()-1; i++) {
if (str[i] == '_' && str[i + 1] == '_') {
flag = true;
break;
}
}
}
if (str.find('_') != string::npos) {
for (int i = 0; i < str.size(); i++) {
if ('A' <= str[i] && str[i] <= 'Z') {
flag = true;
break;
}
}
JavaToC();
}
else {
CToJava();
}
if (flag) cout << "Error!";
else cout << str;
}