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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(string s,t;cin>>s>>t,t!="X";){
		vs ss;
		for(int i=0,j=1;i<s.size();j++){
			if(j==s.size() || isupper(s[j])){
				ss.push_back(s.substr(i,j-i));
				i=j;
			}
			if(s[j]=='_'){
				ss.push_back(s.substr(i,j-i));
				i=++j;
			}
		}
		if(t=="U")
			rep(i,ss.size())
				rep(j,ss[i].size())
					putchar(j==0?toupper(ss[i][j]):tolower(ss[i][j]));
		if(t=="L")
			rep(i,ss.size())
				rep(j,ss[i].size())
					putchar(i&&j==0?toupper(ss[i][j]):tolower(ss[i][j]));
		if(t=="D")
			rep(i,ss.size()){
				cout<<(i?"_":"");
				rep(j,ss[i].size())
					putchar(tolower(ss[i][j]));
			}
		cout<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main( void )
{
	string s;
	string t;
	while ( cin >> s >> t && t != "X" )
	{
		vector <string> list;
		string token;

		// _ª éÈçA_[XRA
		if ( s.find( "_" ) != string::npos )
		{
			token = "";
			for ( int i = 0; i < s.size(); i++ )
			{
				if ( s[i] == '_' )
				{
					list.push_back( token );
					token = "";
				}
				else
				{
					token += s[i];
				}
			}
			list.push_back( token );
		}
		else if ( s[0] >= 'A' && s[0] <= 'Z' )
		{
			token = "";
			s[0] = tolower( s[0] );
			for ( int i = 0; i < s.size(); i++ )
			{
				if ( s[i] >= 'A' && s[i] <= 'Z' )
				{
					list.push_back( token );
					token = "";
					token += tolower( s[i] );
				}
				else
				{
					token += s[i];
				}
			}
			list.push_back( token );
		}
		else if ( s[0] >= 'a' && s[0] <= 'z' )
		{
			token = "";
			for ( int i = 0; i < s.size(); i++ )
			{
				if ( s[i] >= 'A' && s[i] <= 'Z' )
				{
					list.push_back( token );
					token = "";
					token += tolower( s[i] );
				}
				else
				{
					token += s[i];
				}
			}
			list.push_back( token );
		}

		if ( t == "U" )
		{
			for ( int i = 0; i < list.size(); i++ )
			{
				list[i][0] = toupper( list[i][0] );
			}
		}
		else if ( t == "L" )
		{
			for ( int i = 1; i < list.size(); i++ )
			{
				list[i][0] = toupper( list[i][0] );
			}
		}
		else if ( t == "D" )
		{
			for ( int i = 1; i < list.size(); i++ )
			{
				list[i] = "_" + list[i];
			}
		}

		string kotae = "";
		for ( int i = 0; i < list.size(); i++ )
			kotae += list[i];
		cout << kotae << endl;
	}

	return 0;
}

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

using namespace std;

string UOP(string str){
  string ans;
  if('a' <= str[0] && str[0] <= 'z') str[0] = toupper(str[0]);
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == '_'){
      if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
    }
    else ans += str[i];
  }
  return ans;
}

string LOP(string str){
  string ans;
  if('A' <= str[0] && str[0] <= 'Z') str[0] = tolower(str[0]);
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == '_'){
      if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
    }
    else ans += str[i];
  }
  return ans;
}

string DOP(string str){
  string ans;
  for(int i = 0 ; i < str.size() ; i++){
    if('A' <= str[i] && str[i] <= 'Z') str[i] = tolower(str[i]);
    ans += str[i];
    if('A' <= str[i+1] && str[i+1] <= 'Z') ans += '_';
  }
  return ans;
}

int main(){
  string str;
  char op;
  while(cin >> str >> op, op != 'X'){
    if(op == 'U'){
      cout << UOP(str) << endl;
    }
    else if(op == 'L'){
      cout << LOP(str) << endl;
    }
    else if(op == 'D'){
      cout << DOP(str) << endl;
    }
  }
  return 0;
}