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 i, j;

vector <string> word(string str);

int main(void)
{
	string str;
	char type;
	while (cin >> str >> type, type != 'X'){
		int flag = 0;
		vector <string> vs = word(str);
		if (type == 'L'){
			cout << vs[0];
			for (i = 1; i < vs.size(); i++){
				vs[i][0] ^= 32;
				cout << vs[i];
			}
			puts("");
		}
		if (type == 'U'){
			for (i = 0; i < vs.size(); i++){
				vs[i][0] ^= 32;
				cout << vs[i];
			}
			puts("");
		}
		if (type == 'D'){
			for (i = 0; i < vs.size(); i++){
				cout << vs[i];
				if (i + 1 != vs.size()) cout << "_";
			}
			puts("");
		}
	}
	
	return 0;
}

vector <string> word(string str)
{
	vector <string> vs;
	bool flag = false;
	for (i = 0; i < str.size(); i++){
		if (str[i] == '_') {
			flag = true;
			break;
		}
	}
	
	string tmp;
	if (flag){
		for (i = 0; i < str.size(); i++){
			if (str[i] != '_'){
				tmp += (str[i] |= 32);
			}
			else {
				vs.push_back(tmp);
				tmp.clear();
			}
		}
		vs.push_back(tmp);
		return vs;
	}
	
	if ('a' <= str[0] && str[0] <= 'z'){
		for (i = 0; i < str.size(); i++){
			if (!('A' <= str[i] && str[i] <= 'Z')){
				tmp += (str[i] |= 32);
			}
			else {
				vs.push_back(tmp);
				tmp.clear();
				break;
			}
		}
		for (; i < str.size(); i++){
			tmp += (str[i] |= 32);
			if (('A' <= str[i + 1] && str[i + 1] <= 'Z') && i + 1 < str.size()){
				vs.push_back(tmp);
				tmp.clear();
			}
		}
		vs.push_back(tmp);
		return vs;
	}
	
	if ('A' <= str[0] && str[0] <= 'Z'){
		for (i = 0; i < str.size(); i++){
			tmp += (str[i] |= 32);
			if (('A' <= str[i + 1] && str[i + 1] <= 'Z') && i + 1 < str.size()){
				vs.push_back(tmp);
				tmp.clear();
			}
		}
		vs.push_back(tmp);
		return vs;
	}
	
	return vs;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  int strlen,i,j,flag[101];
  char type;
  string str,strout,temp;
  while(1){
    for(i=0;i<101;i++) flag[i]=0;
    cin >> str >> type;
    strlen=str.size();
    strout="";
    if(type=='X') break;
    if(type=='U'){
      for(i=0;i<strlen;i++){
	if(i==0) strout+=str[i]-'a'+'A';
	if(str[i]=='_') str[i+1]=str[i+1]-'a'+'A';
	if(str[i]!='_'&&i>0){
	  strout+=str[i];
	}
      }
    }
    else if(type=='L'){
      if(strlen==1&&str[0]>='a'){
	strout=str[0]-'a'+'A';
      }else{
	for(i=0;i<strlen;i++){
	  if(i==0){
	    if(str[i]<'a'){
	      strout+=str[i]-'A'+'a';
	    }
	    else{
	      strout+=str[i];
	    }
	  }
	  else{
	    if(str[i]=='_') str[i+1]=str[i+1]-'a'+'A';
	    else{
	      strout+=str[i];
	    }
	  }
	}
      }
    }else{
      for(i=0;i<strlen;i++){
	if(i!=0&&str[i]<'a'){
	  flag[i]=1;
	}
      }
      for(i=0;i<strlen;i++){
	if(flag[i]==1){
	  strout+='_';
	}
	if(str[i]<'a'){
	  strout+=str[i]-'A'+'a';
	}
	else{
	  strout+=str[i];
	}
      }
    }
    cout << strout << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<cctype>
#include<cstdlib>
using namespace std;
int main(){
    string str;char type;
    while(cin>>str>>type,str!="EndOfInput"||type!='X'){
        vector<char>ans;ans.push_back(tolower(str[0]));
        for(int i=1;i<str.length();i++){
            if(str[i]!='_'&&islower(str[i])){
                ans.push_back(str[i]);
                continue;
            }
            if(isupper(str[i])){
                if(type=='L'||type=='U')ans.push_back(str[i]);
                else{
                    ans.push_back('_');
                    ans.push_back(tolower(str[i]));
                }
            }
            else{
                i++;
                if(type=='L'||type=='U')ans.push_back(toupper(str[i]));
                else{
                    ans.push_back('_');
                    ans.push_back(str[i]);
                }
            }
        }
        if(type=='U')ans[0]=toupper(ans[0]);
        for(int i=0;i<ans.size();i++)cout<<ans[i];cout<<endl;
    }
    return 0;
}

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

#define to 'A'-'a'
#define small(x) (x) >= 'a' && (x) <= 'z'
#define big(x) (x) >= 'A' && (x) <= 'Z'

int main(){
    string line;
    char s;
    while(1){
        cin >> line >> s;
        if(s == 'X') break;
        if(s == 'U' || s == 'L'){
            for(int i=0;i<line.size();i++){
                if(i == 0 && s == 'U' && small(line[i])) line[i] += to;
                else if(i == 0 && s == 'L' && big(line[i])) line[i] -= to;
                if(line[i] == '_') line[i+1] += to;
            }
            while(line.find("_") != string::npos) line.erase(line.find("_"),1);
        }
        else {
            for(int i=0;i<line.size();i++){
                if(i == 0 && big(line[i])) line[i] -= to;
                else if(big(line[i])) {
                    line[i] -= to;
                    line.insert(i,"_");
                }
            }
        }
        cout << line << endl;
    }
}