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 <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

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

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/

string get_underscore(string inp)
{
	if (inp.find("_") != string::npos)
	{
		return inp;
	}
	
	if (inp[0] < 'a') inp[0] += 32;
	string ret = "";
	for (int i=0; i<inp.length(); i++)
	{
		if (inp[i] < 'a')
		{
			char c = inp[i] + 32;
			ret = ret + "_" + c;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

string upper_camel_case(string inp)
{
	char c = inp[0] - 32;
	string ret = "";
	
	ret += c;
	
	for (int i=1; i<inp.length(); i++)
	{
		if (inp[i] == '_')
		{
			ret += inp[i+1] - 32;
			i++;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

string lower_camel_case(string inp)
{
	string ret = "";
	
	for (int i=0; i<inp.length(); i++)
	{
		if (inp[i] == '_')
		{
			ret += inp[i+1] - 32;
			i++;
		} else {
			ret += inp[i];
		}
	}
	
	return ret;
}

int main()
{
	string name;
	char type;
	
	while (cin >> name >> type)
	{
		if (type == 'X') break;
		
		name = get_underscore(name);
		
		switch (type)
		{
		case 'U':
			cout << upper_camel_case(name) << endl;
			break;
		case 'L':
			cout << lower_camel_case(name) << endl;
			break;
		case 'D':
			cout << name << endl;
			break;
		}
	}
	
	//cout << upper_camel_case("get_user_name") << endl;
	
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
auto to_l(string& str){
  str[0]=tolower(str[0]);
  for(auto i=find(begin(str), end(str), '_'); i!=end(str); i=find(i, end(str), '_')){
    ++i; *i=toupper(*i);
  }
  str.erase(remove(begin(str), end(str), '_'), end(str));
}
auto l_to_u(string& str){
  str[0]=toupper(str[0]);
}
auto l_to_d(string& str){
  for(auto i=find_if(begin(str), end(str), [](const char c){ return isupper(c)!=0; });
    i!=end(str);
    i=find_if(i, end(str), [](const char c){ return isupper(c)!=0; })){
    i=str.insert(i, '_');
    ++i; *i=tolower(*i);
  }
}
int32_t main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str; char c;
  for(cin>>str>>c; c!='X'; cin>>str>>c){
    to_l(str);
    switch(c){
    case 'D': l_to_d(str); break;
    case 'U': l_to_u(str);
    }
    cout<<str<<'\n';
  }
}

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]=='_') flag=1;
	    if(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 <iostream>
#include <string>
using namespace std;
int main(){
  int i,len;
  char type;
  string name,out;
  while(1){
    out="";
    cin >> name >> type;
    if(type=='X') break;
    len=name.size();
    for(i=0;i<len;i++){
      if(i==0){
	if(name[i]<'a'&&type!='U') 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]=='_'&&type!='D'){
	  out+=name[i+1]-'a'+'A';
	  i++;
	}
	else if(name[i]<'a'&&type=='D'){
	  out+='_';
	  out+=name[i]-'A'+'a';
	}else{
	  out+=name[i];
	}
      }
    }
    cout << out << endl;
  }
  return 0;
}