#include<stdio.h> #include<iostream> #include<stack> #include<string.h> using namespace std; int main() { char s[1024] ={0}, temp; fgets(s,1024,stdin); s[strlen(s)-1] = '\0'; int len = strlen(s); stack<char> x; // cout<<s<<endl; int i = 0, flag = 0; x.push('_'); for(i=len-1;i>=0;i--) { if(s[i] == '.') x.push('_'); else x.push(s[i]); if(isdigit(s[i]) && isalpha(s[i-1])) x.push('_'); else if(isalpha(s[i]) && isdigit(s[i-1])) x.push('_'); else if(islower(s[i]) && isupper(s[i-1])) x.push('_'); else if(isupper(s[i]) && islower(s[i-1])) x.push('_'); } x.push('_'); while(!x.empty()) { if(isalpha(x.top())) cout<<(char)toupper(x.top()); else cout<<x.top(); x.pop(); } cout<<endl; return 0; }
#include<iostream>
#include<vector>
#include <stdio.h>
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
vector<string> v_res;
while(1)
{
string str;
getline(cin,str);//¶ÁÈëstring
if(str=="")
break;
string res="";
res +='_';
int count = 1;
bool preIsupper = false;
bool preIsdigit = false;
bool preIspoint = false;
for(int i =0;i<str.length();++i)
{
if(i==0 && isupper(str[i]))
{
res+=str[0];
preIsupper =true;
preIsdigit = false;
preIspoint = false;
}
else if(str[i]=='.')
{
res+='_';
preIsupper =false;
preIsdigit = false;
preIspoint = true;
}
else if(preIspoint)
{
res+=toupper(str[i]);
if(isupper(str[i]))
{
preIsupper =true;
preIsdigit = false;
preIspoint = false;
}
else if(isdigit(str[i]))
{
preIsupper =false;
preIsdigit = true;
preIspoint = false;
}
else if(islower(str[i]))
{
preIsupper =false;
preIsdigit = false;
preIspoint = false;
}
}
else if(preIsupper)
{
if(isupper(str[i]))
{
preIsupper =true;
preIsdigit = false;
preIspoint = false;
if(i==str.length()-1 || (i<str.length()-1 && (isupper(str[i+1]) || isdigit(str[i+1]) || str[i+1]=='.')))
{
res+=str[i];
}
else if(i<str.length()-1 && islower(str[i+1]))
{
res+='_';
res+=toupper(str[i]);
}
else
{
res+=str[i];
}
}
else if(islower(str[i]))
{
res+=toupper(str[i]);
preIsupper = false;
preIsdigit = false;
preIspoint = false;
}
else if(isdigit(str[i]))
{
res+='_';
res+=str[i];
preIsupper = false;
preIsdigit = true;
preIspoint = false;
}
}
else if(preIsdigit)
{
if(isupper(str[i]) || islower(str[i]))
{
res+='_';
res+=str[i];
preIsupper = false;
preIspoint = false;
preIsdigit = false;
if(isupper(str[i]))
preIsupper = true;
}
else
{
res+=str[i];
preIsupper = false;
preIsdigit = true;
preIspoint = false;
}
}
else
{
if(isupper(str[i]) )
{
res+='_';
res+=str[i];
preIsupper = true;
preIsdigit = false;
preIspoint = false;
}
else if(isdigit(str[i]))
{
res+='_';
res+=str[i];
preIsupper = false;
preIsdigit = true;
preIspoint = false;
}
else
{
res+=toupper(str[i]);
preIsupper = false;
preIsdigit = false;
preIspoint = false;
}
}
}
res +='_';
v_res.push_back(res);
}
for(unsigned int i=0;i<v_res.size();++i)
cout<<v_res[i]<<endl;
return 0;
}