Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for s, c := getNextString(scanner), getNextString(scanner); c != "X"; s, c = getNextString(scanner), getNextString(scanner) {
		if strings.Index(s, "_") != -1 {
			fmt.Fprintln(writer, translate(strings.Split(s, "_"), c))
			continue
		}
		ss := make([]string, 0)
		for len(s) > 0 {
			index := nextupper(s[1:])
			ss = append(ss, s[:index+1])
			s = s[index+1:]
		}
		fmt.Fprintln(writer, translate(ss, c))
	}
}
func translate(ss []string, c string) string {
	switch c {
	case "U":
		return u(ss)
	case "L":
		return l(ss)
	case "D":
		return d(ss)
	}
	return ""
}

func nextupper(s string) int {
	n := len(s)
	for i := 0; i < n; i++ {
		if s[i:i+1] == strings.ToUpper(s[i:i+1]) {
			return i
		}
	}
	return n
}
func u(ss []string) string {
	n := len(ss)
	for i := 0; i < n; i++ {
		ss[i] = fmt.Sprintf("%s%s", strings.ToUpper(ss[i][0:1]), ss[i][1:])
	}
	return strings.Join(ss, "")
}
func l(ss []string) string {
	n := len(ss)
	ss[0] = strings.ToLower(ss[0])
	for i := 1; i < n; i++ {
		ss[i] = fmt.Sprintf("%s%s", strings.ToUpper(ss[i][0:1]), ss[i][1:])
	}
	return strings.Join(ss, "")
}
func d(ss []string) string {
	n := len(ss)
	for i := 0; i < n; i++ {
		ss[i] = strings.ToLower(ss[i])
	}
	return strings.Join(ss, "_")
}

C++: #include <iostream>
#include <string>
using namespace std;

int dif='a'-'A';
void outU( string &s ){
  char c;
  for(unsigned int i=0;i<s.size();i++ ){
    c=s.at( i );
    if( i==0 ) c-= dif;
    cout << c;
  }
}

int main(){
  string name, type;
  string names[100];
  int nw;

  while( true ){
    cin >> name >> type;
    //    cout << name << "," << type << endl;

    if( type=="X" ) break;

    for( int i=0;i<100;i++ )names[i]="";

    nw=0;
    char c;
    for( unsigned int i=0; i<name.size();i++ ){
      c = name.at(i);
      if( c== '_' ) nw++;
      else if( c<='Z'){
	c+= dif;
	if( names[nw].size()!=0 ){
	  nw++; names[nw]="";
	}
	names[nw] += c;
      }else
	names[nw] += c;
    }
    if( c!='_' )
      nw++;

    //    cout << "\ndiv "<<name<<endl;
    // for( int i=0;i<nw;i++ )      cout << names[i] << endl;

    if( type=="D" ){
      int i;
      for( i=0;i<nw-1;i++ )
	cout << names[i] << "_" ;
      cout << names[i] << endl;
    }else{
      if( type=="U" ) // テつ湘つ嘉つづδ淌つづδ古つ陛つカテつ偲つ堙つ療δアテつづδ催つ陛δ湘つ甘つキ
	outU( names[0] );
      else
	cout << names[0];
      for( int i=1;i<nw;i++ )
	outU( names[i] );
      cout << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  char S[101],s;
  while(1){
    scanf("%s %c",S,&s);
    if(s=='X') break;
    else if(s=='L' || s=='U'){
      for(int i=0,l=strlen(S);i<l;i++){
	if(s=='L'&&i==0&&S[i]>='A'&&S[i]<='Z'){
	  printf("%c",S[i]-('A'-'a'));
	}else if(S[i]=='_' ||(s=='U'&&i==0&&S[i]>='a'&&S[i]<='z')){
	  if(i!=0)i++;
	  printf("%c",S[i]+ ('A'-'a'));
	}else  printf("%c",S[i]);
      }
    }else if(s=='D'){
      if(S[0]>='A'&&S[0]<='Z')printf("%c",S[0]-('A'-'a'));
      else printf("%c",S[0]);
      for(int i=1,l=strlen(S);i<l;i++){
	if(S[i]>='A'&&S[i]<='Z'){
	  printf("_%c",S[i]-('A'-'a'));
	}else{
	  printf("%c",S[i]);
	}
      }
    }
    puts("");
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  int strlen,i,j,flag[101];
  char type;
  string str,strout,temp;
  while(1){
    for(i=0;i<101;i++) flag[i]=0;
    cin >> str >> type;
    strlen=str.size();
    strout="";
    if(type=='X') break;
    if(type=='U'){
      for(i=0;i<strlen;i++){
	if(i==0) strout+=str[i]-'a'+'A';
	if(str[i]=='_') str[i+1]=str[i+1]-'a'+'A';
	if(str[i]!='_'&&i>0){
	  strout+=str[i];
	}
      }
    }
    else if(type=='L'){
      for(i=0;i<strlen;i++){
	if(i==0){
	  if(str[i]<'a'){
	    strout+=str[i]-'A'+'a';
	  }
	  else{
	    strout+=str[i];
	  }
	}
	else{
	  if(str[i]=='_') str[i+1]=str[i+1]-'a'+'A';
	  else{
	    strout+=str[i];
	  }
	}
      }
    }else{
      for(i=0;i<strlen;i++){
	if(i!=0&&str[i]<'a'){
	  flag[i]=1;
	}
      }
      for(i=0;i<strlen;i++){
	if(flag[i]==1){
	  strout+='_';
	}
	if(str[i]<'a'){
	  strout+=str[i]-'A'+'a';
	}
	else{
	  strout+=str[i];
	}
      }
    }
    cout << strout << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	string s,t;
	while(cin>>s>>t,t!="X"){
		if(t=="L"){
			rep(i,s.size())if(s[i]=='_'){
				s[i+1]=toupper(s[i+1]);
				s.erase(s.begin()+i);
				i--;
			}
			s[0]=tolower(s[0]);
		}else if(t=="U"){
			rep(i,s.size())if(s[i]=='_'){
				s[i+1]=toupper(s[i+1]);
				s.erase(s.begin()+i);
				i--;
			}
			s[0]=toupper(s[0]);
		}else{
			rep(i,s.size())if(i&&isupper(s[i])){
				s[i]=tolower(s[i]);
				s.insert(i,"_");
			}
			s[0]=tolower(s[0]);
		}
		cout<<s<<endl;	
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  char S[101],s;
  while(1){
    scanf("%s %c",S,&s);
    if(s=='X') break;
    else if(s=='L' || s=='U'){
      for(int i=0,l=strlen(S);i<l;i++){
	if(s=='U'&&i==0&&S[i]>='A'&&S[i]<='Z'){
	  printf("%c",S[i]-('A'-'a'));
	}else if(S[i]=='_' ||(s=='U'&&i==0&&S[i]>='a'&&S[i]<='z')){
	  if(i!=0)i++;
	  printf("%c",S[i]+ ('A'-'a'));
	}else  printf("%c",S[i]);
      }
    }else if(s=='D'){
      if(S[0]>='A'&&S[0]<='Z')printf("%c",S[0]-('A'-'a'));
      else printf("%c",S[0]);
      for(int i=1,l=strlen(S);i<l;i++){
	if(S[i]>='A'&&S[i]<='Z'){
	  printf("_%c",S[i]-('A'-'a'));
	}else{
	  printf("%c",S[i]);
	}
      }
    }
    puts("");
  }
}