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<cctype>
#include<algorithm>

using namespace std;

void UpperCamelCase(string&);
void LowerCamelCase(string&);
void UnderScoreCase(string&);
bool IsUpperCase(char);

int main(){
  char c;
  string str;

  while(1){
    cin >> str >> c;

    if(c == 'X') break;
    else if(c == 'U') UpperCamelCase(str);
    else if(c == 'L') LowerCamelCase(str);
    else if(c == 'D') UnderScoreCase(str);

    cout << str << endl;
  }

  return 0;
}

void UpperCamelCase(string& s){
  string::iterator i;

  if(s[0] >= 'a' && s[0] <= 'z')
    s[0] = toupper(s[0]);

  i = s.begin();
  while(1){
    i = find(i, s.end(), '_');
    if(i == s.end()) break;
    i = s.erase(i);
    *i = toupper(*i);
  }
}

void LowerCamelCase(string& s){
  string::iterator i;

  if(s[0] >= 'A' && s[0] <= 'Z')
    s[0] = tolower(s[0]);

  i = s.begin();
  while(1){
    i = find(i, s.end(), '_');
    if(i == s.end()) break;
    i = s.erase(i);
    *i = toupper(*i);
  }
}

void UnderScoreCase(string& s){
  string::iterator i;

  if(s[0] >= 'A' && s[0] <= 'Z')
    s[0] = tolower(s[0]);

  i = s.begin();
  while(1){
    i = find_if(i, s.end(), IsUpperCase);
    if(i == s.end()) break;
    *i = tolower(*i);
    s.insert(i, '_');
  }
}

bool IsUpperCase(char c){
  if(c >= 'A' && c <= 'Z')
    return true;
  else
    return false;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	while (true)
	{
		string s;
		char to;
		cin >> s >> to;
		if (to == 'X')
			break;

		vector<string> words;
		s += '_';
		while (!s.empty())
		{
			s[0] = tolower(s[0]);
			for (int i = 0; i < s.size(); ++i)
			{
				if (s[i] == '_' || isupper(s[i]))
				{
					words.push_back(s.substr(0, i));
					words.back()[0] = words.back()[0];
					s.erase(0, i + (s[i] == '_' ? 1 : 0));
					break;
				}
			}
		}

		string res;
		if (to == 'U' || to == 'L')
		{
			if (to == 'U')
				words[0][0] = toupper(words[0][0]);
			res += words[0];
			for (int i = 1; i < words.size(); ++i)
			{
				words[i][0] = toupper(words[i][0]);
				res += words[i];
			}
		}
		else
			for (int i = 0; i < words.size(); ++i)
				res += words[i] + (i + 1 != words.size() ? "_" : "");
		cout << res << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(void){
  string s;
  char c;
  for(;;){
    cin >> s >> c;
    if(c=='X') break;
    if(s[0]>='A' && s[0]<='Z') s[0]+=32;
    for(int i=1;i<s.size();i++){
      if(s[i]=='_') s[i]=' ';
      else if(s[i]>='A' && s[i]<='Z'){
	s[i]+=32;
	s.insert(i," ");
      }
    }
    if(c=='L'){
      for(int i=0;i<s.size();i++){
	if(s[i]==' ') continue;
	if(i!=0 && s[i-1]==' ') printf("%c",s[i]-32);
	else cout << s[i];
      }
    }
    else if(c=='U'){
      for(int i=0;i<s.size();i++){
	if(s[i]==' ') continue;
	if(i==0 || s[i-1]==' ') printf("%c",s[i]-32);
	else cout << s[i];
      }
    }
    else if(c=='D'){
      for(int i=0;i<s.size();i++){
	if(s[i]==' ') cout << "_";
	else cout << s[i];
      }
    }
    cout << "\n";
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
    char s[1024], type[2];
    
    while (scanf("%s %s", s, type) && type[0] != 'X'){
        char t[1024];
        int resLen = 0;
        
        memset(t, 0, sizeof(t));
        
        for (int i = 0; s[i]; i++){
            if (i == 0){
                if (type[0] == 'U') t[resLen++] = toupper(s[i]);
                else t[resLen++] = tolower(s[i]);
            }
            else {
                if (islower(s[i])){
                    if (s[i - 1] == '_' && type[0] != 'D') t[resLen++] = toupper(s[i]);
                    else t[resLen++] = s[i];
                }
                else if (isupper(s[i])){
                    if (type[0] != 'D') t[resLen++] = s[i];
                    else {
                        t[resLen++] = '_';
                        t[resLen++] = tolower(s[i]);
                    }
                }
                else {
                    if (type[0] == 'D') t[resLen++] = s[i];
                }
            }
        }
        
        printf("%s\n", t);
    }
    
    return (0);
}