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

int main()
{
  string name, type;
  while (cin >> name >> type) {
    if (type == "X")
      break;

    name[0] = tolower(name[0]);
    vector<string> words;
    if (name.find_first_of("_") != string::npos) {
      int s = 0;
      name += "_";
      for (int i = 0; i < name.size(); ++i) {
	if (name[i] == '_') {
	  words.push_back(name.substr(s, i-s));
	  s = i+1;
	}
      }
    } else {
      int s = 0;
      name += "X";
      for (int i = 0; i < name.size(); ++i) {
	if (isupper(name[i])) {
	  words.push_back(name.substr(s, i-s));
	  name[i] = tolower(name[i]);
	  s = i;
	}
      }
    }

    if (type == "D") {
      cout << words[0];
      for (int i = 1; i < words.size(); ++i)
	cout << "_" << words[i];
    } else {
      if (type == "U")
	words[0][0] = toupper(words[0][0]);
      cout << words[0];

      for (int i = 1; i < words.size(); ++i) {
	words[i][0] = toupper(words[i][0]);
	cout << words[i];
      }
    }
    cout << endl;
  }
  return 0;
}

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

vector<string> tokenize(string s) {
    vector<string> ret;
    int beg = 0;
    for(int i=1; i<s.length(); ++i) {
        if(s[i] == '_') {
            ret.push_back(s.substr(beg,i-beg));
            beg = i+1;
        }
        if(s[i] <= 'Z' && s[i] >= 'A') {
            ret.push_back(s.substr(beg,i-beg));
            beg = i;
        }
    }
    if(beg < s.length()) ret.push_back(s.substr(beg));
    return ret;
}

string toL(vector<string> sv) {
    string ret;
    sv[0][0] = tolower(sv[0][0]);
    ret += sv[0];
    for(int i=1; i<sv.size(); ++i) {
        sv[i][0] = toupper(sv[i][0]);
        ret += sv[i];
    }
    return ret;
}

string toU(vector<string> sv) {
    string ret;
    for(int i=0; i<sv.size(); ++i) {
        sv[i][0] = toupper(sv[i][0]);
        ret += sv[i];
    }
    return ret;
}

string toD(vector<string> sv) {
    string ret;
    sv[0][0] =  tolower(sv[0][0]);
    ret += sv[0];
    for(int i=1; i<sv.size(); ++i) {
        ret += "_";
        sv[i][0] = tolower(sv[i][0]);
        ret += sv[i];
    }
    return ret;
}

int main() {
    string input,op;
    while(cin>>input>>op) {
        if(op == "X") break;
        vector<string> tokens;
        tokens = tokenize(input);
        if(op == "U") cout<<toU(tokens)<<endl;
        else if(op == "L") cout<<toL(tokens)<<endl;
        else if(op == "D") cout<<toD(tokens)<<endl;
    }
}

C++: #include <iostream>
#include <string>

using namespace std;

void solve()
{
	string str;
	char c;
	while(cin >> str)
	{
		cin >> c;
		string Answer;
		int size = str.size();
		if(c == 'X')
		{
			break;
		}
		else if(c == 'L')
		{
			if('A' <= str[0] && str[0] <= 'Z')
			{
				Answer += str[0] - 'A' + 'a';
			}
			else if('a' <= str[0] && str[0] <= 'z')
			{
				Answer += str[0];
			}
			bool flag = false;
			for(int i = 1; i < size; ++i)
			{
				if(str[i] == '_')
				{
					flag = true;
					continue;
				}
				if(flag && 'a' <= str[i] && str[i] <= 'z')
				{
					Answer += str[i] - 'a' + 'A';
					flag = false;
					continue;
				}
				Answer += str[i];
				flag = false;
			}
		}
		else if(c == 'U')
		{
			if('A' <= str[0] && str[0] <= 'Z')
			{
				Answer += str[0];
			}
			else if('a' <= str[0] && str[0] <= 'z')
			{
				Answer += str[0] - 'a' + 'A';
			}
			bool flag = false;
			for(int i = 1; i < size; ++i)
			{
				if(str[i] == '_')
				{
					flag = true;
					continue;
				}
				if(flag && 'a' <= str[i] && str[i] <= 'z')
				{
					Answer += str[i] - 'a' + 'A';
					flag = false;
					continue;
				}
				Answer += str[i];
				flag = false;
			}
		}
		else if(c == 'D')
		{
			if('A' <= str[0] && str[0] <= 'Z')
			{
				Answer += str[0] - 'A' + 'a';
			}
			else if('a' <= str[0] && str[0] <= 'z')
			{
				Answer += str[0];
			}
			for(int i = 1; i < size; ++i)
			{
				if(str[i] == '_')
				{
					Answer += '_';
					continue;
				}
				if('A' <= str[i] && str[i] <= 'Z')
				{
					Answer += '_';
					Answer += str[i] - 'A' + 'a';
					continue;
				}
				Answer += str[i];
			}
		}
		cout << Answer << endl;
	}
}

int main()
{
	solve();
	return(0);
}