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<string>
#include<vector>
#include<iostream>

#define	pb	push_back

using namespace std;

vector<string> split(string s){
	int n=s.length();

	bool d=false;
	for(int i=0;i<n;i++)	if(s[i]=='_')	d=true;

	vector<string> ans;
	if(d){
		s+='_';
		n++;
		int bef=-1;
		for(int i=0;i<n;i++){
			if(s[i]=='_' && ~bef){
				ans.pb(s.substr(bef,i-bef));
				bef=-1;
			}
			else{
				if(bef==-1)	bef=i;
			}
		}
		return ans;
	}
	else{
		s[0]=tolower(s[0]);
		s+='Q';
		n++;
		int bef=0;
		for(int i=0;i<n;i++){
			if(isupper(s[i])){
				ans.pb(s.substr(bef,i-bef));
				s[i]=tolower(s[i]);
				bef=i;
			}
		}
		return ans;
	}
}

int main(){
	while(1){
		string s;
		char c;
		cin>>s>>c;

		vector<string> part=split(s);
		int n=part.size();
		if(c=='U'){
			for(int i=0;i<n;i++){
				part[i][0]=toupper(part[i][0]);
				cout<<part[i];
			}
			cout<<endl;
		}
		else if(c=='L'){
			for(int i=0;i<n;i++){
				if(i>0)	part[i][0]=toupper(part[i][0]);
				cout<<part[i];
			}
			cout<<endl;
		}
		else if(c=='D'){
			for(int i=0;i<n;i++){
				if(i>0)	cout<<'_';
				cout<<part[i];
			}
			cout<<endl;
		}
		else	break;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

bool foo1(char t){
	if('A'<=t&&t<='Z') return true;
	return false;
}

int main(){
	string s;
	char t;
	while(cin>>s>>t,t!='X'){
		vector<string> vs;
		int x=0;
		rep(i,s.size()){
			if(i==0) continue;
			if(foo1(s[i])){
				vs.PB(s.substr(x,i-x));
				x=i;
			}
			else if(s[i]=='_'){
				vs.PB(s.substr(x,i-x));
				x=i+1;
			}

		}
		vs.PB(s.substr(x));
		rep(i,vs.size()){
			rep(j,vs[i].size()){
				if(foo1(vs[i][j])){
					vs[i][j]+='a'-'A';
				}
			}
		}
		if(t=='U'){
			rep(i,vs.size()){
				vs[i][0]+='A'-'a';
				cout<<vs[i];
			}
			// cout<<endl;
		}
		else if(t=='L'){
			rep(i,vs.size()){
				if(i) vs[i][0]+='A'-'a';
				cout<<vs[i];
			}
		}
		else if(t=='D'){
			rep(i,vs.size()){
				if(i){
					cout<<"_";
				}
				cout<<vs[i];
			}
		}
		cout<<endl;
	}
}

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

int main()
{
	char s[101], o;
	while (cin >> s >> o)
	{
		if (o == 'X') break;
		int k = 0, u = 0;
		char t[100][101] = {""};
		t[k][u] = ('A' <= s[0] && s[0] <= 'Z') ? s[0]-'A'+'a' : s[0];
		++u;
		for (int i = 1; i < strlen(s); ++i)
		{
			if ('A' <= s[i] && s[i] <= 'Z')
			{
				t[k][u] = '\0';
				++k, u = 0;
				t[k][u] = s[i]-'A'+'a';
				++u;
			}
			else if (s[i] == '_')
			{
				t[k][u] = '\0';
				++k, u = 0;
			}
			else if (s[i] == '\0')
			{
				t[k][u] = '\0';
				break;
			}
			else
			{
				t[k][u] = s[i];
				++u;
			}
		}
		int m = k;
		k = 0;

		char r[201] = "";
		if (o == 'U' || o == 'L')
		{
			for (int i = 0; i <= m; ++i)
			{
				for (int j = 0; j < strlen(t[i]); ++j)
				{
					if (i == 0 && j == 0) r[k] = (o == 'U') ? 'A'+t[i][j]-'a' : t[i][j];
					else if (j == 0) r[k] = 'A'+t[i][j]-'a';
					else r[k] = t[i][j];
					++k;
				}
			}
			r[k] = '\0';
		}
		else
		{
			for (int i = 0; i <= m; ++i)
			{
				for (int j = 0; j < strlen(t[i]); ++j)
				{
					r[k] = t[i][j];
					++k;
				}
				r[k] = '_';
				++k;
			}
			r[k-1] = '\0';
		}

		cout << r << 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 == "D") {
					name[prev] = tolower(name[prev]);
					if(prev) ans += '_';
				}
				else {
					name[prev] = toupper(name[prev]);
				}

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

		ans += name.substr(prev);
		if(type == "L") ans[0] = tolower(ans[0]);
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}