rt
我的测试
代码如下:
#include<bits/stdc++.h>
using namespace std;
int read(){
int num=0,fl=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-') fl=-1;ch=getchar();}
while(isdigit(ch)){num=num*10+ch-'0';ch=getchar();}
return num*fl;
}
string s;
int type;
int check(string s){
if(s[0]<'a'||s[0]>'z')
return 0;
for(int i=1;i<s.length();++i){
if(s[i]>='A'&&s[i]<='Z'){
if(type==-1)//已经是C++了
return 0;
else
type=1;//是java
}
else if(s[i]=='_'){
if(s[i-1]=='_')
return 0;
if(type==1)
return 0;
else
type=-1;
}
else if(s[i]>'z'||s[i]<'a'){
return 0;
}
}
if(s[s.length()-1]=='_')
return 0;
if(type==0)
type=1;
return type;
}
int main(){
cin>>s;
type=check(s);
if(!type){
cout<<"Error!";
return 0;
}
if(type==1){
for(int i=0;i<s.length();++i){
if(s[i]<='Z'&&s[i]>='A'){
cout<<'_'<<char(s[i]+32);
}
else{
cout<<s[i];
}
}
}
else{
for(int i=0;i<s.length();++i){
if(s[i]=='_'){
cout<<char(s[i+1]-32);
++i;
}
else{
cout<<s[i];
}
}
}
return 0;
}