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 <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	char buf[101],result[500],type;
	int p,i;

	while(true){
		scanf("%s %c",buf,&type);
		if(type == 'X')break;

		p = 0;
		switch(type){
		case 'U':
			for(i = 0;buf[i] != '\0';){
				if(i == 0){
					if(buf[i] >= 97 && buf[i] <= 122){
						result[p++] = buf[i] - 32;
					}else{
						result[p++] = buf[i];
					}
					i++;
				}else if(buf[i] == '_'){
					i++;
					if(buf[i] >= 97 && buf[i] <= 122){
						result[p++] = buf[i] - 32;
					}else{
						result[p++] = buf[i];
					}
					i++;
				}else{
					if(buf[i] >= 65 && buf[i] <= 90){ //??§???????????´???
						if(buf[i-1] >= 97 && buf[i-1] <= 122){//??£????????????
							result[p++] = buf[i];
						}else{
							result[p++] = buf[i] - 32;
						}
					}else{
						result[p++] = buf[i];
					}
					i++;
				}
			}
			result[p] = '\0';

			printf("%s\n",result);
			break;
		case 'L':
			for(i = 0;buf[i] != '\0';){
				if(i == 0){
					if(buf[i] >= 65 && buf[i] <= 90){
						result[p++] = buf[i] + 32;
					}else{
						result[p++] = buf[i];
					}
					i++;
				}else if(buf[i] == '_'){
					i++;
					if(buf[i] >= 97 && buf[i] <= 122){
						result[p++] = buf[i] - 32;
					}else{
						result[p++] = buf[i];
					}
					i++;
				}else{
					if(buf[i] >= 65 && buf[i] <= 90){ //??§???????????´???
						if(buf[i-1] >= 97 && buf[i-1] <= 122){//??£????????????
							result[p++] = buf[i];
						}else{
							result[p++] = buf[i] - 32;
						}
					}else{
						result[p++] = buf[i];
					}
					i++;
				}
			}
			result[p] = '\0';

			printf("%s\n",result);
			break;
		case 'D':
			for(i = 0;buf[i] != '\0';){
				if(i == 0){
					if(buf[i] >= 65 && buf[i] <= 90){
						result[p++] = buf[i] + 32;
					}else{
						result[p++] = buf[i];
					}
					i++;
				}else if(buf[i] == '_'){
					result[p++] = buf[i];
					i++;
				}else{
					if(buf[i] >= 65 && buf[i] <= 90){ //??§???????????´???
						if((buf[i-1] == '_') || (buf[i-1] >= 97 && buf[i-1] <= 122)){//??£?????????????????£???????????????
							result[p++] = '_';
							result[p++] = buf[i] + 32;
						}else{
							result[p++] = buf[i] + 32;
						}
					}else{
						result[p++] = buf[i];
					}
					i++;
				}
			}
			result[p] = '\0';


			printf("%s\n",result);
			break;
		}

	}


    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    string name;
    char type;
    string UP;
    for (int i = 0; i < 26; i++) {
        UP += 'A' + i;
    }

    while (cin >> name >> type) {
        if (type == 'U') {
            stringstream ss;
            for (auto& i : name) if (i == '_') i = ' ';
            ss << name;
            string str;
            while (ss >> str) {
                str[0] = str[0] - 'a' + 'A';
                cout << str;
            }
            cout << endl;
        } else if (type == 'L') {
            stringstream ss;
            for (auto& i : name) if (i == '_') i = ' ';
            ss << name;
            string str;
            ss >> str;
            cout << str;
            while (ss >> str) {
                str[0] = str[0] - 'a' + 'A';
                cout << str;
            }
            cout << endl;
        } else if (type == 'D'){
            for (int i = 0; i < name.size(); i++) {
                if (UP.find(name[i]) != string::npos) {
                    name[i] = name[i] - 'A' + 'a';
                    name.insert(i, " ");
                }
            }
            stringstream ss;
            ss << name;
            string str;
            ss >> str;
            cout << str;
            while (ss >> str) {
                cout << "_" << str;
            }
            cout << endl;
        } else {
          break;
        }
    }

    return 0;
}

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

string toLowerCamel(string str){
    string l = "";
    char pre = ' ';
    for ( int i = 0; i < str.size(); i++ ){
	if ( isalpha(str[i]) ){
	    if ( pre == '_' ) l += toupper(str[i]);
	    else l += str[i];
	}
	pre = str[i];
    }
    l[0] = tolower(l[0]);
    return l;
}

main(){
    string name;
    char com;
    while(1){
	cin >> name >> com;
	if ( com == 'X' ) break;
	string l = toLowerCamel(name);
	if ( com == 'L' ) cout << l << endl;
	else if ( com == 'U' ){
	    l[0] = toupper(l[0]);
	    cout << l << endl;
	} else if ( com == 'D' ){
	    for ( int i = 0; i < l.size(); i++ ){
		if ( 'A' <= l[i] && l[i] <= 'Z' ){
		    cout << "_";
		    cout << (char)(tolower(l[i]));
		} else cout << l[i];
	    }
	    cout << endl;
	}
    }
}