-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJAVAC.cpp
More file actions
54 lines (46 loc) · 795 Bytes
/
Copy pathJAVAC.cpp
File metadata and controls
54 lines (46 loc) · 795 Bytes
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 <cctype>
using namespace std;
int Convert(string x)
{
bool flag1 = false, flag2 = false;
if (x[0] == '_' || isupper(x[0]) || x[x.size()-1] == '_' || isdigit(x[0]))
{
cout<<"Error!"<<endl;
return -1;
}
for (int i = 0; i < x.size(); i++)
if (flag1 && flag2)
{
cout<<"Error!"<<endl;
return -1;
}
else if (x[i] == '_')
{
if (x[i+1] == '_' || isupper(x[i+1]))
{
cout<<"Error!"<<endl;
return -1;
}
flag1 = true;
x.erase(i, 1);
x[i] = (char)((int)x[i] - 32);
}
else if (isupper(x[i]))
{
flag2 = true;
x.insert(i, "_");
x[++i] = (char)((int)x[i] + 32);
}
cout<<x<<endl;
return 1;
}
int main()
{
ios::sync_with_stdio(false);
string x;
while (cin>>x)
Convert(x);
return 0;
}