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<algorithm>
#include<cstdio>
#include<cctype>
using namespace std;



int main(){
  string name;
  char type,pre_type;

  while(true){
    cin >> name >> type;
    if(type == 'X')break;
    for(int i=0;i<name.size();i++){
      if(type == 'U'){
	if(i == 0){
	  cout << (char)toupper(name[i]);
	  continue;
	}
	if(name[i] == '_'){
	  name[i+1] = toupper(name[i+1]);
	  continue;
	}
	cout << name[i];
      }
      else if(type == 'L'){
	if(i == 0){
	  cout << (char)tolower(name[i]);
	  continue;
	}
	if(name[i] == '_'){
	  name[i+1] = (char)toupper(name[i+1]);
	  continue;
	}
	cout << name[i];
      }
      else if(type == 'D'){
	if(i == 0){
	  cout << (char)tolower(name[i]);
	  continue;
	}
	if(isupper(name[i])){
	  cout << "_" << (char)tolower(name[i]);
	  continue;
	}
	cout << name[i];
      }
    }

  cout << endl;


  }



}

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

int main(){
  vector < char > ch;
  vector < char > order;
  vector < char > ans;
  char odr,D,U,L,_;
  char moji;
  string str;
  int i,j,len,len2;
  int flag,p = 0;
  while(1){
    ans.clear();
    order.clear();
    
    cin >> str >> odr ;
    if( str == "EndOfInput" && odr == 'X' ) break;
    int l = str.size();
    flag = 0;
    for( i = 0; i < l; i++ ){
      if( str[i] == '_' ) flag = 1;
    }
  
    
    if( islower( str[0] ) &&  flag == 1 ) order.push_back('D');
    else if( isupper( str[0] ) ) order.push_back('U');
    else if( islower( str[0] ) ) order.push_back('L');

    for( i = 0; i < l; i++ ) ch.push_back( str[i] );
    
    order.push_back(odr);

    // int len3 = order.size();
    //for( i = 0; i < len3; i++ ) cout << order[i] << " " ;
    //cout << endl;

    for( i = 0; i < l; i++ ){
      if( order[p] == 'U' && order[p+1] == 'U' )ans.push_back( str[i] );

      
      if( order[p] == 'U' && order[p+1] == 'L' ){
	if( i == 0 ) ans.push_back( tolower(str[0]) );
	else ans.push_back( str[i] );
      }

      if( order[p] == 'U' && order[p+1] == 'D' ){
	if( i == 0 ) ans.push_back( tolower(str[0]) );
	else if( isupper( str[i+1] ) ){
	  ans.push_back( str[i] );
	  ans.push_back('_');
	  ans.push_back( tolower( str[i+1] ) );
	  i++;
	}else ans.push_back( str[i] );

      }

      if( order[p] == 'L' && order[p+1] == 'U' ){
	if( i == 0 ) ans.push_back( toupper(str[0]) );
	else ans.push_back( str[i] );
      }

      if( order[p] == 'L' && order[p+1] == 'L' )ans.push_back( str[i] );


      if( order[p] == 'L' && order[p+1] == 'D' ){
	if( isupper( str[i+1] ) ){
	  ans.push_back( str[i] );
	  ans.push_back('_');
	  ans.push_back( tolower( str[i+1] ) );
	  i++;
	}else ans.push_back( str[i] );
      }

      if( order[p] == 'D' && order[p+1] == 'U' ){
	if( i == 0 ){
	  ans.push_back( toupper( str[0]) );
	}else{
	if( str[i] == '_' ){
	  ans.push_back( toupper(str[i+1]) );
	  i++;
	}else ans.push_back( str[i] );
	}
      }
      if( order[p] == 'D' && order[p+1] == 'L' ){
	if( str[i] == '_' ){
	  ans.push_back( toupper(str[i+1]) );
	  i++;
	}
	else ans.push_back( str[i] );
      }

      if ( order[p] == 'D' && order[p+1] == 'D' )ans.push_back( str[i] );
    }
 
    len2 = ans.size();
   
    for( i = 0; i < len2; i++ ) cout << ans[i];
    cout << endl;
   
    
  }
  
  return 0;
    }

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	string s;
	char get_type, to_type;
	while (cin >> s >> to_type) {
		if (to_type == 'X')return 0;
		if ((int)s[0] < 95)get_type = 'U';
		else {
			get_type = 'L';
			for (char i : s)if (i == '_')get_type = 'D';
		}
		if (get_type == to_type)cout << s << endl;
		else {
			for (int i = 0; i < s.size(); i++) {
				if (i == 0) {
					if (to_type == 'U')cout << (char)(s[0] - 32);
					else if (get_type != 'U')cout << s[0];
					else cout << (char)(s[0] + 32);
				}
				else if (s[i] == '_') {
					i++;
					cout << (char)(s[i] - 32);
				}
				else if (s[i] < 95 && to_type == 'D')cout << '_' << (char)(s[i] + 32);
				else cout << s[i];
			}
			cout << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
char type;

int main(){
	while (cin >> s >> type){
		string ans = "";
		if (type == 'X')break;
		if (type == 'L'){
			REP(i, s.size()){
				if (i == 0)ans += tolower(s[i]);
				else {
					if (s[i] == '_'){
						i++;
						ans += toupper(s[i]);
					}
					else ans += s[i];
				}
			}
		}
		else if (type == 'U'){
			REP(i, s.size()){
				if (i == 0)ans += toupper(s[i]);
				else{
					if (s[i] == '_'){
						i++;
						ans += toupper(s[i]);
					}
					else ans += s[i];
				}
			}
		}
		else{
			REP(i, s.size()){
				if (i != 0 && s[i] >= 'A'&&s[i] <= 'Z')ans += '_';
				ans += tolower(s[i]);
			}
		}
		cout << ans << endl;
	}
}