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(void){
  string str;
  char c;
  while(cin >> str >> c){
    int t;
    vector<string> v;
    string buf = "";
    bool isOneWord = true;
    if(c == 'X')break;
    if('A' <= str[0] && str[0] <= 'Z'){
      //upper camel case
      for(int j=0;j<str.size();j++){
	if('A' <= str[j] && str[j] <= 'Z'){
	  if(j!=0)v.push_back(buf);
	  buf = "";
	  buf += str[j] - 'A' + 'a';
	}else{
	  buf += str[j];
	}
      }
      v.push_back(buf);
    }else{
      for(int i=0;i<str.size();i++){
	if(str[i] == '_'){
	  //snake case
	  for(int j=0;j<str.size();j++){
	    if(str[j] == '_'){
	      v.push_back(buf);
	      buf = "";
	    }else{
	      buf += str[j];
	    }
	  }
	  v.push_back(buf);
	  isOneWord = false;
	  break;
	}else if('A' <= str[i] && str[i] <= 'Z'){
	  //lower cames case
	  for(int j=0;j<str.size();j++){
	    if('A' <= str[j] && str[j] <= 'Z'){
	      if(j!=0)v.push_back(buf);
	      buf = "";
	      buf += str[j] - 'A' + 'a';
	    }else{
	      buf += str[j];
	    }
	  }
	  v.push_back(buf);
	  isOneWord = false;
	  break;
	}
      }
      if(isOneWord){
	v.push_back(str);
      }
    }
    //convert
    if(c == 'L'){
      for(int i=0;i<v.size();i++){
	if(i==0){
	  cout << v[i];
	}else{
	  v[i][0] -= 'a' - 'A';
	  cout << v[i];
	}
      }
    }else if(c == 'U'){
      for(int i=0;i<v.size();i++){
	v[i][0] -= 'a' - 'A';
	cout << v[i];
      }
    }else{
      for(int i=0;i<v.size();i++){
	cout << v[i];
	if(i != v.size()-1) cout << "_";
      }
    }
    cout << endl;
  }
}

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

using namespace std;

int main(){

	string str;
	while(1){
		getline(cin,str);
		string name = str.substr(0,str.size()-2);
		char type = str[str.size()-1];
		if(type=='L'){
			if(name[0] >= 'a' && name[0] <= 'z'){
				for(int i = 0; i < name.size(); i++){
					if(name[i] == '_'){
						cout << (char)(name[i+1]-'a'+'A') << flush;
						i++;
					}
					else{
						cout << name[i] << flush;
					}
				}
				cout<<endl;
			}
			else{
				cout << (char)(name[0]-'a'+'A') << flush;
				for(int i = 1; i < name.size(); i++){
					cout << name[i]<<flush;
				}
			}
		}
		else if(type=='U'){
			if(name[0] >= 'a' && name[0] <= 'z'){
				cout << (char)(name[0]-'a'+'A') << flush;
				for(int i = 1; i < name.size(); i++){
					if(name[i] == '_'){
						cout << (char)(name[i+1]-'a'+'A') << flush;
						i++;
					}
					else{
						cout << name[i]<<flush;
					}
				}
				cout<<endl;
			}
			else{
				cout << name[0] << flush;
				for(int i = 1; i < name.size(); i++){
					cout << name[i]<<flush;
				}
			}
		}
		else if(type=='D'){
			if(name[0] >= 'a' && name[0] <= 'z'){
				for(int i = 0; i < name.size(); i++){
					if(name[i] >= 'A' && name[i] <= 'Z'){
						cout <<'_'<<flush;
						cout << (char)(name[i]+'a'-'A') << flush;
						i++;
					}
					else{
						cout << name[i] << flush;
					}
				}
				cout<<endl;
			}
			else{
				cout << (char)(name[0]-'A'+'a') << flush;
				for(int i = 1; i < name.size(); i++){
					if(name[i] >= 'A' && name[i] <= 'Z'){
						cout <<'_'<<flush;
						cout << (char)(name[i] - 'A'+'a') << flush;
					}
					else
						cout << name[i]<<flush;
				}
				cout << endl;
			}
		}
		else
			break;
		//cout<<endl;
	}

	return 0;
}