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 <vector>
#include <string>
#include <algorithm>
using namespace std;

bool isLower( char c ){
	return ( c >= 'a' && c <= 'z' )? true : false ;
}

bool isUpper(char c){
	return ( c >= 'A' && c <= 'Z' )? true : false ;
}

vector<string> splitString(const string& s){
	string s_ = "";
	vector<string> vc;

	for(int i=0 ; i<(int)s.size() ; i++ ){
		if( s[i] == '_' ){
			vc.push_back( s_ );
			s_ = "";
		}else if( isLower( s[i] ) ){
			s_.push_back( s[i] );
			if( i == (int)s.size()-1 ){
				vc.push_back( s_ );
			}
		}else if( isUpper( s[i] ) ){
			vc.push_back( s_ );
			s_ = "";
			s_.push_back( s[i] );
			if( i == (int)s.size()-1 ){
				vc.push_back( s_ );
			}
		}
	}
	return vc;
}

string solve(string s, string c){
	vector<string> vc = splitString( s );
	string str = "";
	
	for(int i=0 ; i<(int)vc.size() ; i++ ){
		if( !vc[i].empty() ){
			if( c == "D" ){
				if( isUpper(vc[i][0]) )
					vc[i][0] += 'a'-'A';
				str += vc[i];
				if( i != (int)vc.size()-1 )
					str.push_back('_');
			}else{
				if( isLower(vc[i][0]) )
					vc[i][0] -= 'a'-'A';
				str += vc[i];
			}
		}
	}
	if( c == "L" && isUpper(str[0]) ){
		str[0] += 'a'-'A';
	}
	return str;
}

int main(){
	string s, c;
	while( cin >> s >> c , c != "X" ){
		cout << solve( s , c ) << endl;
	}
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

string ULtoD(string s){
  stringstream ss;
  ss << (char)tolower(s[0]);
  FOR(i, 1, s.length()){
    if(isupper(s[i])) ss << '_' << (char)tolower(s[i]);
    else ss << (char)tolower(s[i]);
  }
  return ss.str();
}

string DtoUL(string s, char t){
  stringstream ss;
  ss << (char)(t == 'U' ? toupper(s[0]) : s[0]);
  FOR(i, 1, s.length()){
    if(s[i] == '_') ss << (char)toupper(s[++i]);
    else ss << s[i];
  }
  return ss.str();
}

int main() {
  string s; char t;
  while(cin >>s >>t && t != 'X'){
    char bt;
    if(isupper(s[0])) bt = 'U';
    else if(s.find('_') != string::npos) bt = 'D';
    else bt = 'L';
    if(bt == 'U'){
      if(t == 'L') s[0] = tolower(s[0]);
      if(t == 'D') s = ULtoD(s);
    } else if(bt == 'L'){
      if(t == 'U') s[0] = toupper(s[0]);
      if(t == 'D') s = ULtoD(s);
    } else s = DtoUL(s, t);
    cout <<s <<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;

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

    if(S=='X') break;

    else  if(S=='L'){
      if(str[0]>='A' && str[0]<='Z') str[0]+=32;
      for(int i=0;i<str.size();i++){
	if(str[i]=='_' && str[i+1]>='a' && str[i+1]<='z' ) str[i+1]-=32;
      }
      for(int i=0;i<str.size();i++){
	if(str[i]=='_') continue;
	else cout<<str[i];
      }
      cout<<endl;
    }
    
    else  if(S=='U') {
      if(str[0]>='a' && str[0]<='z') str[0]-=32;
    
    for(int i=0;i<str.size();i++){
    if(str[i]=='_') str[i+1]-=32;
  }
  for(int i=0;i<str.size();i++){
	if(str[i]=='_') continue;
	else cout<<str[i];
      }
      cout<<endl;
      
    }
    
  else  if(S=='D'){
    for(int i=0;i<str.size();i++){
      if(str[i]>=65 && str[i]<=90){
	str[i]+=32;
      }
      if(i>0 && str[i+1]>=65 && str[i+1]<=90){
	cout<<str[i]<<"_";
      }
      else cout<<str[i];
    }
    cout<<endl;
  }
  }
  return 0;
  }

C++: #include <cctype>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(string name, type; cin >> name >> type && type != "X";) {
		string ans = "";
		int prev = 0;
		for(unsigned i = 0; i < name.size(); ++i) {
			if(name[i] == '_' || isupper(name[i])) {
				if(type == "U") {
					name[prev] = toupper(name[prev]);
					ans += name.substr(prev, i - prev);
				}
				else if(type == "L") {
					if(prev) name[prev] = toupper(name[prev]);
					else name[prev] = tolower(name[prev]);
					ans += name.substr(prev, i - prev);
				}
				else {
					name[prev] = tolower(name[prev]);
					if(prev) ans += '_';
					ans += name.substr(prev, i - prev);
				}

				prev = i;
				if(name[i] == '_') ++prev;
			}
		}
		if(type == "D") {
			name[prev] = tolower(name[prev]);
			ans += '_';
		}
		else {
			name[prev] = toupper(name[prev]);
		}
		ans += name.substr(prev);
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}