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>

using namespace std;

int main(int argc, char *argv[]) {
  string s;
  char c;
  while (true) {
    cin >> s >> c;
    if (c == 'U') {
      if (s.find('_', 0) == string::npos &&
          'a' <= s[0] && s[0] <= 'z')
        s[0] += ('A'-'a');
      else
        for (int i = 0; i < s.size(); i++)
          if (s[i] == '_') {
            s[i+1] += ('A'-'a');
            s.erase(i, 1);
          } else if (i == 0 && 'a' <= s[0] && s[0] <= 'z') {
            s[i] += ('A'-'a');
          }
      cout << s << endl;
    } else if (c == 'L') {
      if (s.find('_', 0) == string::npos &&
          'A' <= s[0] && s[0] <= 'Z')
        s[0] -= ('A'-'a');
      else
        for (int i = 0; i < s.size(); i++)
          if (s[i] == '_') {
            s[i+1] += ('A'-'a');
            s.erase(i, 1);
          }
      cout << s << endl;
    } else if (c == 'D') {
      for (int i = 0; i < s.size(); i++)
        if (i == 0 && 'A' <= s[i] && s[i] <= 'Z') {
          s[i] -= ('A'-'a');
        } else if ('A' <= s[i] && s[i] <= 'Z') {
          s[i] -= ('A'-'a');
          s.insert(i, 1, '_');
        }
      cout << s << endl;
    } else {
      break;
    }
  }
  return 0;
}

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;
				}
				cout<<endl;
			}
		}
		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;
				}
				cout<<endl;
			}
		}
		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;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s,t;
main(){
	while(cin>>s>>t,s!="EndOfInput"){
		if(t=="L"){
			r(i,s.size())if(s[i]=='_')s[i+1]=s[i+1]-32;
			r(i,s.size())if(isalpha(s[i]))cout<<s[i];
		}
		else if(t=="U"){
			s[0]=s[0]-32;
			cout<<s;
		}
		else{
			s[0]=s[0]+32;
			r(i,s.size()){
				if(s[i]<='Z')cout<<'_'<<(char)(s[i]+32);
				else cout<<s[i];
			}
		}
		cout<<endl;
	}
}

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

string name, type;

vector<string> split(string name) {
	vector<string> ret;
	string word;
	
	for (int i = 0; i < name.length(); i++) {
		if (name[i] == '_' || ('A' <= name[i] && name[i] <= 'Z')) {
			if (word.length() > 0) ret.push_back(word);
			word = "";
		}
		if ('A' <= name[i] && name[i] <= 'Z') word += name[i] + 32;
		else if (name[i] != '_') word += name[i];
	}
	ret.push_back(word);
	return ret;
}

int main() {
	while (cin >> name >> type) {
		char t = type[0];
		
		vector<string> names = split(name);
		
		if (t == 'X') break;
		
		if (t == 'U' || t == 'L') {
			for (int i = (t == 'L'); i < names.size(); i++) {
				if ('a' <= names[i][0] && names[i][0] <= 'z')
					names[i][0] = names[i][0] - 32;
			}
		}
		if (t == 'D') {
			for (int i = 0; i < (int)names.size() - 1; i++) {
				names[i] += '_';
			}
		}
		
		for (int i = 0; i < names.size(); i++) {
			cout << names[i];
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  int i,len,flag;
  char type;
  string name,out;
  while(1){
    flag=0;
    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]<'a'||name[i]=='_') flag=1;
	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];
      }
    }
    if(type=='L'&&flag==0) out[0]=out[0]-'a'+'A';
    cout << out << endl;
  }
  return 0;
}