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 <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];
				if(i==s.size()-1) 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;
}

C++: #include <iostream>
#include <cctype>
#include <vector>
 
using namespace std;
 
int len;
 
string UpperCamelCase(vector<string> v){
    string res = "";
 
    for(int i = 0 ; i < len ; i++){
	if(islower(v[i][0])){
	    v[i][0] = toupper(v[i][0]);
	}
	res += v[i];
    }
 
    return res;
}
 
string LowerCamelCase(vector<string> v){
    string res = v[0];
 
    for(int i = 1 ; i < len ; i++){
	if(islower(v[i][0])){
	    v[i][0] = toupper(v[i][0]);
	}
	res += v[i];
    }
 
    return res;
}
 
string Under(vector<string> v){
    string res = v[0];
 
    for(int i = 1 ; i < len ; i++){
	res += '_' + v[i];
    }
   
    return res;
}
 
int main(){
    string s;
    char order;
 
    while(cin >> s >> order, order != 'X'){
	if(isupper(s[0])){
	    s[0] = tolower(s[0]);
	}
	s += '_';
 
	vector<string> v;
	int pos = 0;
	len = (int)s.size();
 
	for(int i = 0 ; i < len ; i++){
	    if(isupper(s[i])){
		s[i] = tolower(s[i]);
		v.push_back(s.substr(pos,i-pos));
		pos = i;
	    }else if(s[i] == '_'){
		v.push_back(s.substr(pos,i-pos));
		pos = i + 1;
	    }
	}
 
	len = (int)v.size();
     
	if(order == 'U'){
	    cout << UpperCamelCase(v) << endl;
	}else if(order == 'L'){
	    cout << LowerCamelCase(v) << endl;
	}else{
	    cout << Under(v) << endl;
	}
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

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> ws;
        string tmp;
        rep(i,s.size()){
            if(isupper(s[i])){
                if(i==0){
                    tmp+=tolower(s[i]);
                    continue;
                }
                ws.push_back(tmp);
                tmp=tolower(s[i]);
            }else if(s[i]=='_'){
                ws.push_back(tmp);
                tmp="";
            }else tmp+=s[i];
        }
        ws.push_back(tmp);
        if(c=='L'){
            rep(i,ws.size()){
                if(i) cout<<upperCamel(ws[i]);
                else cout<<ws[i];
            }
            cout<<endl;
        }else if(c=='U'){
            rep(i,ws.size()){
                cout<<upperCamel(ws[i]);
            }
            cout<<endl;
        }else if(c=='D'){
            rep(i,ws.size()){
                if(i)cout<<"_";
                cout<<ws[i];
            }
            cout<<endl;
        }
    }
}

C++: #include<iostream>
#include<string>
#include<ctype.h>
using namespace std;
int main(){
	string s;
	char t;
	while(true){
	cin>>s>>t;
	if(t=='X')break;
	if(t=='U'){
		if(s[0]>='a'&&s[0]<='z')s[0]-=32;
		cout<<s[0];
		for(int i=1;i<s.size();i++)cout<<s[i];
		cout<<endl;
	}
	if(t=='L'){
		bool big=false;
		for(int i=0;i<s.size();i++){
			if(big){
				s[i]-=32;
				big=false;
			}
			if(s[i]=='_')big=true;
			else cout<<s[i];
		}
		cout<<endl;
	}
	if(t=='D'){
		if(s[0]>='A'&&s[0]<='Z')s[0]+=32;
		cout<<s[0];
		for(int i=1;i<s.size();i++){
			if(s[i]>='A'&&s[i]<='Z'){
				cout<<"_";
				s[i]+=32;
			}
			cout<<s[i];
		}
		cout<<endl;
	}
	}
	return 0;
}