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 len,i,flag;
  string str,out;
  char type;
  while(1){
    flag=0;
    out="";
    cin >> str >> type;
    len=str.size();
    if(type=='X') break;
    if(type=='U'){
      for(i=0;i<len;i++){
	if(i==0&&str[i]>='a') out+=str[i]-'a'+'A';
	else{
	  if(str[i]=='_'){
	    out+=str[i+1]-'a'+'A';
	    i++;
	  }else out+=str[i];
	}
      }
    }
    else if(type=='L'){
	for(i=0;i<len;i++){
	  if(i==0&&str[i]<'a') out+=str[i]-'A'+'a';
	  else{
	    if(str[i]=='_'||str[i]<'a') flag=1;
	    if(str[i]=='_'){
	      out+=str[i+1]-'a'+'A';
	      i++;
	    }else out+=str[i];
	  }
	}
	//	if(flag==0) out[0]=out[0]-'a'+'A';
      }
      else if(type=='D'){
	for(i=0;i<len;i++){
	  if(i==0&&str[i]<'a') out+=str[i]-'A'+'a';
	  else{
	    if(str[i]<'a'){
	      out+='_';
	      out+=str[i]-'A'+'a';
	    }else out+=str[i];
	  }
	}
      }
    cout << out << endl;
  }
  return 0;
}

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

using namespace std;

string LowerCamelCaseDiv2(string S)
{
    string T;
    
    for(int i = 0; i < S.size(); i++)
    {
        if(i == 0)
        {
            T += tolower(S[i]);
        }  
        else if(S[i - 1] == '_')
        {
            T += toupper(S[i]);
        }
        else if(S[i] != '_')
        {
            T += S[i];
        }
    }
    
    return T;
}

string UpperCamelCaseDiv2(string S)
{
    string T;
    
    for(int i = 0; i < S.size(); i++)
    {
        if(i == 0)
        {
            T += toupper(S[i]);
        }  
        else if(S[i - 1] == '_')
        {
            T += toupper(S[i]);
        }
        else if(S[i] != '_')
        {
            T += S[i];
        }
    }
    
    return T;
}

string UnderLineDiv2(string S)
{
    string T;
    
    for(int i = 0; i < S.size(); i++)
    {
        if(i != 0 && isupper(S[i]))
        {
            T += '_' + tolower(S[i]);
        }
        else
        {
            T += S[i];
        }
    }
    
    return T;
}

int main()
{
    string S, T;
    
    while(true)
    {
        cin >> S >> T;
        
        if(T == "X") { break; }
        
        if(T == "L") { cout << LowerCamelCaseDiv2(S) << endl; }
        if(T == "U") { cout << UpperCamelCaseDiv2(S) << endl; }
        if(T == "D") { cout << UnderLineDiv2(S) << endl; }
    }
    
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdlib>
using namespace std;

int main() {
  
  string str; char op;
  while(cin>>str>>op) {
    if(op == 'X') break;
    for(int i=0; i<(int)str.size(); i++) {
      if(str[i] == '_') { str[i] = ' '; }
      else if(isupper(str[i])) {
        char ch = tolower(str[i]);
        str = str.substr(0, i) + " " + ch + str.substr(i+1);
      }
      else { str[i] = tolower(str[i]); }
    }
    stringstream ss(str);
    string ans;
    bool fsted = 0;
    while(ss >> str) {
      if(op == 'L') {
        if(fsted) { ans+=toupper(str[0]); ans+=str.substr(1); }
        else ans+=str;
        fsted = 1;
      }
      if(op == 'U') {
        ans+=toupper(str[0]); ans+=str.substr(1);
      }
      if(op == 'D') {
        if(fsted) ans+='_';
        ans+=str;
        fsted = 1;
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <ctype.h>
#include <vector>
using namespace std;

string solve(vector<string> v,char t){
	string ret;
	switch(t){
	case 'U':
		for(int i=0;i<v.size();i++){
			for(int j=0;j<v[i].length();j++){
				v[i][j] = tolower(v[i][j]);
			}
			v[i][0] = toupper(v[i][0]);
			ret += v[i];
		}
		return ret;
	case 'L':
		for(int i=0;i<v.size();i++){
			for(int j=0;j<v[i].length();j++){
				v[i][j] = tolower(v[i][j]);
			}
			if(i)v[i][0] = toupper(v[i][0]);
			ret += v[i];
		}
		return ret;
	case 'D':
		for(int i=0;i<v.size();i++){
			if(i)ret+="_";
			for(int j=0;j<v[i].length();j++){
				v[i][j] = tolower(v[i][j]);
			}
			ret+=v[i];
		}
		return ret;
	}
}

int main(){
	char type;
	string s;
	string t;
	while(cin >> s >> type,type != 'X'){
		vector<string> data;
		if(~s.find("_")){
			for(int i=0;i<s.length();i++){
				if(s[i]=='_'){
					s[i] = ' ';
				}
			}
			stringstream ss(s);
			while(ss >> t)data.push_back(t);
		}else{
			for(int i=0;i<s.length();i++){
				if(isupper(s[i])){
					s.insert(i," ");
					i++;
				}
			}
			stringstream ss(s);
			while(ss >> t)data.push_back(t);
		}
		cout << solve(data,type) << endl;
	}
}