Java vs C++
YOYO
posted @ 2008年11月24日 06:26
in 【ICPC】解题报告
with tags
模拟
, 1979 阅读
PKU 3157:http://acm.pku.edu.cn/JudgeOnline/problem?id=3157
-
#include<iostream>
-
using namespace std;
-
-
int main(){
-
char str[500];
-
while(cin>>str){
-
int length = strlen(str);
-
bool flag = true;
-
bool cpp = false;
-
bool java = false;
-
char s[500];
-
int i,j,n = 0;
-
if(str[0]>='A'&&str[0]<='Z'||str[0]=='_'){
-
flag = false;
-
goto result;
-
}
-
j = 1;
-
while(str[j]!='_'&&(!(str[j]>='A'&&str[j]<='Z')))j++;
-
if(str[j]=='_'){
-
cpp = true;
-
}else{
-
java = true;
-
}
-
for(i=0;i<length;i++){
-
if(cpp){
-
if(str[i]=='_'){
-
i++;
-
if(i==length||str[i]>='A'&&str[i]<='Z'||str[i]=='_'){
-
flag = false;
-
goto result;
-
}else{
-
s[n++]=str[i]-'a'+'A';
-
}
-
}else{
-
s[n++]=str[i];
-
}
-
}else{
-
if(str[i]=='_'){
-
flag = false;
-
goto result;
-
}
-
if(str[i]>='A'&&str[i]<='Z'){
-
s[n++]='_';
-
s[n++]=str[i]-'A'+'a';
-
}else{
-
s[n++]=str[i];
-
}
-
}
-
}
-
s[n]='\0';
-
result:
-
if(flag){
-
cout<<s<<endl;
-
}else{
-
cout<<"Error!"<<endl;
-
}
-
}
-
return 0;
-
}