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<cctype>
#include<string>
#include<vector>
using namespace std;

vector<string> decompose(string s){
  vector<string> res;
  string tmp;
  tmp = s[0];
  
  for(int i=1;i<s.size();i++){
    if(isupper(s[i])){
      res.push_back(tmp);
      tmp = s[i];
    }else if(s[i] == '_'){
      res.push_back(tmp);
      tmp = "";
    }else{
      tmp += s[i];
    }
  }
  res.push_back(tmp);
  return res;
}

string unite(vector<string> v,char c){
  string res;

  for(int i=0;i<v.size();i++){
    if(c == 'D' || (c == 'L' && i==0)){
      v[i][0] = tolower(v[i][0]);
    }else{
      v[i][0] = toupper(v[i][0]);
    }

    if(c == 'D' && i!=0)res += "_";
    res += v[i];
  }
  return res;
}

int main(){
  string s;
  char c;

  while(cin >> s >> c, c!='X'){
    vector<string> v = decompose(s);
    cout << unite(v,c) << endl;
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	string name,type;
	int i;
	while(cin>>name>>type,type!="X"){
		if(isupper(name[0])){
			if(type=="U"){
				cout<<name<<endl;
			}else if(type=="L"){
				name[0]^=' ';
				cout<<name<<endl;
			}else{
				cout<<(char)(name[0]^' ');
				for(i=1;i<name.size();i++){
					if(isupper(name[i])){
						cout<<"_"<<(char)(name[i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}
		}else if(name.find("_")==string::npos){
			if(type=="U"){
				name[0]^=' ';
				cout<<name<<endl;
			}else if(type=="L"){
				cout<<name<<endl;
			}else{
				for(i=0;i<name.size();i++){
					if(isupper(name[i])){
						cout<<"_"<<(char)(name[i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}
		}else{
			if(type=="U"){
				cout<<(char)(name[0]^' ');
				for(i=1;i<name.size();i++){
					if(name[i]=='_'){
						cout<<(char)(name[++i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}else if(type=="L"){
				for(i=0;i<name.size();i++){
					if(name[i]=='_'){
						cout<<(char)(name[++i]^' ');
					}else{
						cout<<name[i];
					}
				}
				cout<<endl;
			}else{
				cout<<name<<endl;
			}
		}
	}
	return 0;
}

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>
using namespace std;

string upperCamel(string& s){
	return (char)(s[0]-'a'+'A')+s.substr(1,s.size());
}

int main(void){
	string s;
	while(cin>>s){
		char c;cin>>c;
		if(c=='X')break;
		vector<string> splited;
		string tmp;
		for(int i=0;i<s.size();++i){
			if('A'<=s[i]&&s[i]<='Z'){
				if(i==0){
					tmp+=s[i]-'A'+'a';
					continue;
				}
				splited.push_back(tmp);
				tmp=s[i]-'A'+'a';
			}else if(s[i]=='_'){
				splited.push_back(tmp);
				tmp="";
			}else tmp+=s[i];
		}
		splited.push_back(tmp);
		if(c=='L'){
			for(int i=0;i<splited.size();++i){
				if(i) cout<<upperCamel(splited[i]);
				else cout<<splited[i];
			}
			cout<<endl;
		}else if(c=='U'){
			for(int i=0;i<splited.size();++i){
				cout<<upperCamel(splited[i]);
			}
			cout<<endl;
		}else if(c=='D'){
			for(int i=0;i<splited.size();++i){
				if(i)cout<<"_";
				cout<<splited[i];
			}
			cout<<endl;
		}
	}
	return 0;
}