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++: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;

static const double EPS = 1e-8;

int main(){
	string str;
	char conv;
	while(cin>>str){
		cin >> conv;

		if(conv == 'X') break;
		//under score
		if(count(str.begin(),str.end(),'_')){
			if(conv == 'L'){
				//str[0] = 'A' + (str[0]-'a');
				string res="";
				for(int i=0;i+1<str.size();i++){
					if(str[i]=='_' && ('a' <= str[i+1] && str[i+1] <= 'z')){
						str[i+1]='A'+(str[i+1]-'a');
						i++;
					}
				}

				string::iterator it = remove(str.begin(),str.end(),'_');
				str.erase(it,str.end());
			}
			else if(conv == 'U'){
				str[0] = 'A' + (str[0]-'a');
				for(int i=0;i+1<str.size();i++){
					if(str[i]=='_' && ('a' <= str[i+1] && str[i+1] <= 'z')){
						str[i+1]='A'+(str[i+1]-'a');
					}
				}

				remove(str.begin(),str.end(),'_');
			}
		}
		//Upper CamelCase
		else if('A' <= str[0] && str[0] <= 'Z'){
			if(conv == 'L'){
				str[0] = 'a' + (str[0]-'A');
			}
			else if(conv == 'D'){
				string res="";
				str[0] = 'a' + (str[0]-'A');

				res.push_back(str[0]);
				for(int i=1;i<str.size();i++){
					if('A' <= str[i] && str[i] <= 'Z'){
						res.push_back('_');
						res.push_back('a' + (str[i]-'A'));
					}
					else{
						res.push_back(str[i]);
					}
				}

				str = res;
			}

		}
		//Lower CamelCase
		else{
			if(conv == 'U'){
				str[0] = 'A' + (str[0]-'a');
			}
			else if(conv == 'D'){
				string res="";
				str[0] = 'a' + (str[0]-'a');
				res.push_back(str[0]);
				for(int i=1;i+1<str.size();){
					if('A' <= str[i+1] && str[i+1] <= 'Z'){
						res.push_back('_');
						res.push_back(str[i+1]-'A');
						i+=2;
					}
					else{
						res.push_back(str[i]);
						i++;
					}
				}
				str = res;
			}
		}

		cout << str << endl;
	}
}

C++: while true do
  identifier, role = gets.chomp.split(' ')
  break if role == 'X'

  words = Array.new
  if identifier[0] =~ /[A-Z]/ then
    words = identifier.scan(/[A-Z][a-z]*/).map {|x| x.downcase }
  elsif identifier.include? '_' then
    words = identifier.split '_'
  else
    words = identifier.scan(/(?:^[a-z]*)|(?:[A-Z][a-z]*)/).map {|x| x.downcase }
  end

  if role == 'U'
    puts words.map {|x| x.capitalize }.join
  elsif role == 'L'
    print words.shift
    puts words.map {|x| x.capitalize }.join
  elsif role == 'D'
    puts words.join '_'
  end
end

C++: #include <algorithm>
#include <iostream>
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int i=0;
  string s,t;
  for(;cin >> s >> t,t!="X";){
  if(find(s.begin(),s.end(),'_')!=s.end()){
    for(i=0;i<s.length();i++)
      if(s[i]=='_'){
        if(s[i+1]=='_'||s[i+1]==0){cout << "Error!" << endl;return 0;}
        s.erase(i,1),s[i]-=0x20;
      }
    if(t=="U")s[0]-=0x20;
    cout << s << endl;
  }else{
    if(t=="U")s[0]-=0x20;
    else s[0]+=0x20;
    if(t=="D")
      for(i=0;i<s.length();i++)
        if(between('A',s[i],'Z'))s.insert(i,1,'_'),s[++i]+=0x20;
    cout << s << endl;
  }
  }
}

C++: #include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	string s;
	string::iterator i;
	char c;
	int x;
	while(cin>>s>>c,c-'X')
	{
		s[0]=toupper(s[0]);
		while(x=s.find('_'),x!=string::npos)
			s.erase(x,1),s[x]=toupper(s[x]);
		if(c-'U')s[0]=tolower(s[0]);
		if(c=='D')
			for(i=s.begin();(i=find_if(i,s.end(),ptr_fun(isupper)))!=s.end();++i)
				*i=tolower(*i),s.insert(i,'_');
		cout<<s<<endl;
	}
	return 0;
}