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<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//split delimiter??§?????????
vector<string> split(const string &input, char delimiter) {
	vector<string> ret;
	istringstream stream(input);
	string s;
	while (getline(stream, s, delimiter)) ret.push_back(s);
	return ret;
}
string stoupper(string s) { transform(s.begin(), s.end(), s.begin(), ::toupper); return s; }
string stolower(string s) { transform(s.begin(), s.end(), s.begin(), ::tolower); return s; }

signed main() {
	for (string s, t; cin >> s >> t&&t != "X";) {
		vector<string> a;
		if (s.find("_") != string::npos) {
			a = split(s, '_');
		}
		else {
			int l = 0;
			rep(i, 1, s.size()) {
				if (isupper(s[i])) {
					a.push_back(stolower(s.substr(l, i - l)));
					l = i;
				}
			}
			a.push_back(stolower(s.substr(l, s.size())));
		}
		string ans = "";
		if (t == "L") {
			ans += a[0];
			rep(i, 1, a.size()) {
				a[i][0] = toupper(a[i][0]);
				ans += a[i];
			}
		}
		else if (t == "U") {
			rep(i, 0, a.size()) {
				a[i][0] = toupper(a[i][0]);
				ans += a[i];
			}
		}
		else {
			ans += a[0];
			rep(i, 1, a.size()) {
				ans += "_" + a[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

char Aa(char a, bool b) {
	//b ??§??????
	if (b) {
		if (a >= 'a')return a - 32;
		return a;
	}
	else {
		if (a <= 'Z')return a + 32;
		return a;
	}
}
int main() {
	string a; char b;
	while (cin >> a >> b, b != 'X') {
		vector<string>c; string d; 
		d += a[0];
		for (int i = 1; i < a.length();i++) {
			char e = a[i];
			if (e == '_') { c.push_back(d); d = ""; }
			else if (e <= 'Z') { c.push_back(d); d = ""; d += e; }
			else d += e;
		}
		c.push_back(d);
		switch (b)
		{
		case 'U':
			for (string i : c) {
				cout << Aa(i[0], true);
				for (int x = 1; x < i.length(); x++) {
					cout << i[x];
				}
			}
			cout << endl; break;
		case 'L':
			for (int j = 0; j < c.size(); j++) {
				if (j)cout << Aa(c[j][0], true);
				else cout << Aa(c[j][0], false);
				for (int i = 1; i < c[j].length(); i++)cout << c[j][i];
			}
			cout << endl; break;
		case 'D':
			for (int j = 0; j < c.size(); j++) {
				if (j)cout << '_';
				cout << Aa(c[j][0], false);
				for (int i = 1; i < c[j].length(); i++)cout << c[j][i];
			}
			cout << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  int i,len;
  char type;
  string name,out;
  while(1){
    out="";
    cin >> name >> type;
    if(type=='X') break;
    len=name.size();
    for(i=0;i<len;i++){
      if(i==0){
	if(name[i]<'a') out+=name[i]-'A'+'a';
	else if(name[i]>='a'&&type=='U') out+=name[i]-'a'+'A';
	else out+=name[i];
      }
      else{
	if(name[i]=='_'){
	  out+=name[i+1]-'a'+'A';
	  i++;
	}
	else if(name[i]<'a'&&type=='D'){
	  out+='_';
	  out+=name[i]-'A'+'a';
	}else out+=name[i];
      }
    }
    cout << out << endl;
  }
  return 0;
}