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>
#include <vector>

using namespace std;

int main() {
	string s;
	char c;
	string abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string abc2 = "abcdefghijklmnopqrstuvwxyz";
	while (cin >> s >> c) {
		if (c == 'X') {
			break;
		}
		vector<string> ss;
		if (s.find("_") != string::npos) {
			string sa = "";
			for (int i = 0; i < s.size(); i++) {
				if (s[i] == '_') {
					ss.push_back(sa);
					sa = "";
				} else {
					sa += s[i];
				}
			}
			ss.push_back(sa);
		} else {
			bool h = false;
			for (int i = 0; i < 26; i++) {
				if (s[0] == abc[i]) {
					h = true;
					break;
				}
			}
			if (h) {
				string sb = "";
				for (int i = 0; i < s.size(); i++) {
					bool h2 = false;
					for (int j = 0; j < 26; j++) {
						if (s[i] == abc[j]) {
							h2 = true;
							if (sb == "") {
							} else {
								ss.push_back(sb);
							}
							sb = "";
							sb += abc2[j];
							break;
						}
					}
					if (!h2) {
						sb += s[i];
					}
				}
				ss.push_back(sb);
			} else {
				string sc = "";
				for (int i = 0; i < s.size(); i++) {
					bool h2 = false;
					for (int j = 0; j < 26; j++) {
						if (s[i] == abc[j]) {
							h2 = true;
							ss.push_back(sc);
							sc = "";
							sc += abc2[j];
							break;
						}
					}
					if (!h2) {
						sc += s[i];
					}
				}
				ss.push_back(sc);
			}
		}
		string s2 = "";
		if (c == 'U') {
			for (int i = 0; i < ss.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (ss[i][0] == abc2[j]) {
						ss[i][0] = abc[j];
						break;
					}
				}
				s2 += ss[i];
			}
		} else if (c == 'L') {
			s2 += ss[0];
			for (int i = 1; i < ss.size(); i++) {
				for (int j = 0; j < 26; j++) {
					if (ss[i][0] == abc2[j]) {
						ss[i][0] = abc[j];
						break;
					}
				}
				s2 += ss[i];
			}
		} else {
			for (int i = 0; i < ss.size(); i++) {
				if (s2 != "") {
					s2 += "_";
				} 
				s2 += ss[i];
			}
		}
		cout << s2 << endl;
	}
	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) {
                if (UP.find(str[0]) == string::npos)
                    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) {
                if (UP.find(str[0]) == string::npos)
                    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 <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] = toupper(str[0]);
                cout << str;
            }
            cout << endl;
        } else if (type == 'L') {
            stringstream ss;
            for (auto& i : name) if (i == '_') i = ' ';
            ss << name;
            string str;
            ss >> str;
            str[0] = tolower(str[0]);
            cout << str;
            while (ss >> str) {
                str[0] = toupper(str[0]);
                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;
}