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 <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

bool isUSCase(const std::string &s){
    return s.find("_") != std::string::npos;
}

bool isUCCase(const std::string &s){
    return std::isupper(s[0]);
}

bool isLCCase(const std::string &s){
    return !isUSCase(s) && std::islower(s[0]);
}

int main(){
    std::string s;
    char c;

    while(std::cin >> s >> c, c != 'X'){

        if(isUSCase(s)){
            if(c == 'U'){
                s[0] = std::toupper(s[0]);
                int pos = 0;
                while(pos = s.find("_", pos), pos != std::string::npos){
                    s.replace(pos, 2, 1, std::toupper(s[pos+1]));
                    pos++;
                }
            }else if(c == 'L'){
                int pos = 0;
                while(pos = s.find("_", pos), pos != std::string::npos){
                    s.replace(pos, 1, "");
                    s[pos] = std::toupper(s[pos]);
                }
            }else if(c == 'D'){
            
            }
        }else if(isUCCase(s)){
            if(c == 'U'){
            
            }else if(c == 'L'){
                s[0] = std::tolower(s[0]);
            }else if(c == 'D'){
                s[0] = std::tolower(s[0]);
                std::string _s = "";
                REP(i, s.size()){
                    if(std::isupper(s[i]) && i > 0){
                        _s += "_";
                        s[i] = std::tolower(s[i]);
                    }
                    _s += s[i];
                }
                s = _s;
            }
        }else if(isLCCase(s)){
            if(c == 'U'){
                s[0] = std::toupper(s[0]);
            }else if(c == 'L'){
            
            }else if(c == 'D'){
                std::string _s = "";
                REP(i, s.size()){
                    if(std::isupper(s[i])){
                        _s += '_';
                        s[i] = std::tolower(s[i]);
                    }
                    _s += s[i];
                }
                s = _s;
            }        
        }

        std::cout << s << std::endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

using State = string::const_iterator;

string expr(State &itr, int mode){
    string res = "";
    res.push_back(*itr);
    ++itr;
    if(mode==0){
        res[0] = toupper(res[0]);
    }else{
        res[0] = tolower(res[0]);
    }
    while(1){
        if(islower(*itr)){
            res.push_back(*itr);
            ++itr;
        }else{
            break;
        }
    }
    if(mode==0 || mode==1){
        if(*itr == '_') ++itr;
    }else{
        if(isalpha(*itr)) res.push_back('_');
    }
    return res;
}

int main(){
    string s;
    char op;
    while(cin >> s >> op){
        if(op == 'X') break;
        string ans = "";
        int m;
        if(op == 'U') m = 0;
        if(op == 'L') m = 1;
        if(op == 'D') m = 2;
        State begin = s.begin();
        while(begin != s.end()){
            ans += expr(begin,m);
            if(m==1) m = 0;
        }
        cout << ans << endl;
    }
    return 0;
}

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

void str_U(string s){
	string S="";
	for(int i=0;i<s.size();i++){
		if(s[i]=='_'){
			i++;
			if('a'<=s[i]&&s[i]<='z'){
				S+=(s[i]-'a'+'A');
			}
			else{
				S+=s[i];
			}
		}
		else{
			S+=s[i];
		}
	}
	if('a'<=S[0] && S[0]<='z'){
		S[0]-='a';
		S[0]+='A';
	}
	cout<<S<<endl;
}
void str_L(string s){
	string S="";
	for(int i=0;i<s.size();i++){
		if(s[i]=='_'){
			i++;
			if('a'<=s[i]&&s[i]<='z'){
				S+=(s[i]-'a'+'A');
			}
			else{
				S+=s[i];
			}
		}
		else{
			S+=s[i];
		}
	}
	if('A'<=S[0] && S[0]<='Z'){
		S[0]-='A';
		S[0]+='a';
	}
	cout<<S<<endl;
}
void str_D(string s){
	string S="";
	for(int i=0;i<s.size();i++){
		if('A'<=s[i]&&s[i]<='Z'){
			if(i!=0)S+="_";
			S+=(s[i]-'A'+'a');
		}
		else{
			S+=s[i];
		}
	}
	cout<<S<<endl;
}


int main(){
	
	string s;
	char c;
	
	while(cin>>s>>c){
		if(c=='X')break;
		if(c=='U')str_U(s);
		if(c=='L')str_L(s);
		if(c=='D')str_D(s);
		
	}
	
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	string::iterator i;
	char c;
	int x;
	while(cin>>s>>c,c-'X')
	{
		s[0]=toupper(s[0]);
		while(x=s.find('_'),x!=string::npos)
			s.erase(x,1),s[x]=toupper(s[x]);
		if(c-'U')s[0]=tolower(s[0]);
		if(c=='D')
			for(i=s.begin();(i=find_if(i,s.end(),isupper))!=s.end();++i)
				*i=tolower(*i),s.insert(i,'_');
		cout<<s<<endl;
	}
	return 0;
}