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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  char c;
  while(cin >> s >> c && c != 'X'){
    if(c != 'D'){
      rep(i,s.size()){
        if(s[i] == '_'){
          s[i+1] = toupper(s[i+1]);
        }
      }
      if(c == 'U'){
        s[0] = toupper(s[0]);
      }
      FindErase(s,'_');
    }
    else{
      string ans ;
      rep(i,s.size()){
        if(isupper(s[i]) && i != 0){
          ans +=  "_";
        }
        ans += tolower(s[i]);
      }
      s = ans;
    }
    cout << s << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF (1<<22)

int main(){
  while(1){
    string str;
    getline(cin,str);
    int len = str.size();
    char type = str[len-1];
    if(type == 'X') break;
    string ans = "";
    for(int i=0;i<len-2;i++){
      if(i == 0){
	if(type == 'L' || type == 'D'){
	  if(str[i] >= 'A' && str[i] <= 'Z') ans += str[i]+32;
	  else ans += str[i];
	} else {
	  if(str[i] >= 'a' && str[i] <= 'z') ans += str[i]-32;
	  else ans += str[i];
	}
      }
      else if(str[i] >= 'A' && str[i] <= 'Z'){
	if(type == 'D') {
	  ans += '_';
	  ans += (str[i]+32);
	}
	else ans += str[i];
      }
      else if(str[i] == '_'){
	if(type == 'D') ans += str[i];
	else {
	  i++;
	  ans += str[i]-32;
	}
      }
      else ans += str[i];
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){

	string str;
	while(1){
		getline(cin,str);
		string name = str.substr(0,str.size()-2);
		char type = str[str.size()-1];
		if(type=='L'){
			if(name[0] >= 'a' && name[0] <= 'z'){
				for(int i = 0; i < name.size(); i++){
					if(name[i] == '_'){
						cout << (char)(name[i+1]-'a'+'A') << flush;
						i++;
					}
					else{
						cout << name[i] << flush;
					}
				}
				cout<<endl;
			}
			else{
				cout << (char)(name[0]+'a'-'A') << flush;
				for(int i = 1; i < name.size(); i++){
					cout << name[i]<<flush;
				}
				cout<<endl;
			}
		}
		else if(type=='U'){
			if(name[0] >= 'a' && name[0] <= 'z'){
				cout << (char)(name[0]-'a'+'A') << flush;
				for(int i = 1; i < name.size(); i++){
					if(name[i] == '_'){
						cout << (char)(name[i+1]-'a'+'A') << flush;
						i++;
					}
					else{
						cout << name[i]<<flush;
					}
				}
				cout<<endl;
			}
			else{
				cout << name[0] << flush;
				for(int i = 1; i < name.size(); i++){
					cout << name[i]<<flush;
				}
				cout<<endl;
			}
		}
		else if(type=='D'){
			if(name[0] >= 'a' && name[0] <= 'z'){
				for(int i = 0; i < name.size(); i++){
					if(name[i] >= 'A' && name[i] <= 'Z'){
						cout <<'_'<<flush;
						cout << (char)(name[i]+'a'-'A') << flush;
						i++;
					}
					else{
						cout << name[i] << flush;
					}
				}
				cout<<endl;
			}
			else{
				cout << (char)(name[0]-'A'+'a') << flush;
				for(int i = 1; i < name.size(); i++){
					if(name[i] >= 'A' && name[i] <= 'Z'){
						cout <<'_'<<flush;
						cout << (char)(name[i] - 'A'+'a') << flush;
					}
					else
						cout << name[i]<<flush;
				}
				cout << endl;
			}
		}
		else
			break;
		//cout<<endl;
	}

	return 0;
}