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 <cstring>
#include <string.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <cctype>
using namespace std;
int main(){
  char op;
  string str;
  while(cin >> str >> op, op != 'X'){
    bool flag[str.size()];
    memset(flag, 0, sizeof(flag));
    for(int i = 0 ; i < str.size() ; i++){
      if('A' <= str[i] && str[i] <= 'Z' ||
	 str[i] == '_') flag[i] = 1;
    }

    if(op != 'D'){
      if(op == 'U'){
	if('a' <= str[0] && str[0] <= 'z') str[0] = toupper(str[0]);
	for(int i = 0 ; i < str.size() ; i++){
	  if(str[i] == '_'){
	    str[i] = 0;
	    if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
	  }
	}
      }
      
      if(op == 'L'){
	if('A' <= str[0] && str[0] <= 'Z') str[0] = tolower(str[0]);
	for(int i = 0 ; i < str.size() ; i++){
	  if(flag[i] == 1 && str[i] == '_'){
	    str[i] = 0;
	    if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
	  }
	}
      }
      cout << str;
    }
    
    if(op == 'D'){
      for(int i = 0 ; i < str.size() ; i++){
	if('A' <= str[i] && str[i] <= 'Z') str[i] = tolower(str[i]);
	if(flag[i] == 1 && i != 0){
	  cout << '_';
	}
	cout << str[i];
      }
    }  
    cout << endl;   
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <string>
#include <algorithm>
#include <ctype.h>
using namespace std;
int main(){
  char op;
  string str;
  while(cin >> str >> op, op != 'X'){
    bool flag[str.size()];
    memset(flag, 0, sizeof(flag));
    for(int i = 0 ; i < str.size() ; i++){
      if('A' <= str[i] && str[i] <= 'Z' ||
	 str[i] == '_') flag[i] = 1;
    }

    if(op != 'D'){
      if(op == 'U'){
	if('a' <= str[0] && str[0] <= 'z') str[0] = toupper(str[0]);
	for(int i = 0 ; i < str.size() ; i++){
	  if(str[i] == '_'){
	    str[i] = 0;
	    if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
	  }
	}
      }
      
      if(op == 'L'){
	if('A' <= str[0] && str[0] <= 'Z') str[0] = tolower(str[0]);
	for(int i = 0 ; i < str.size() ; i++){
	  if(flag[i] == 1 && str[i] == '_'){
	    str[i] = 0;
	    if('a' <= str[i+1] && str[i+1] <= 'z') str[i+1] = toupper(str[i+1]);
	  }
	}
      }
      cout << str;
    }
    
    if(op == 'D'){
      for(int i = 0 ; i < str.size() ; i++){
	if('A' <= str[i] && str[i] <= 'Z') str[i] = tolower(str[i]);
	if(flag[i] == 1 && i != 0){
	  cout << '_';
	}
	cout << str[i];
      }
    }  
    cout << endl;   
  }
  return 0;
}

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

string s ;
char ans[200] ;

int main(){
	
	char t ;
	
	while( cin >> s >> t ){
		if( t == 'X' ) break ;
		
		int p = 1 ;
		
		if( s[0] <= 90 && t != 'U' ) ans[0] = s[0] +32 ;
		else if( s[0] >= 97 && t == 'U' ) ans[0] = s[0] -32 ;
		else ans[0] = s[0] ;
		for( int i=1 ; i<s.size() ; i++ ){
			if( s[i] == '_' && t != 'D' ){
				ans[p] = s[i+1] -32 ;
				i++ ;
			}
			else if( s[i] <= 90 && t == 'D' ){
				ans[p] = '_' ;
				ans[p+1] = s[i] +32 ;
				p++ ;
			} else ans[p] = s[i] ;
			
			p++ ;
		}
		
		for( int i=0 ; i<p ; i++ ){
			cout << ans[i] ;
		}cout << endl ;
	}
	
return 0 ;
}

C++: #include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<functional>
using namespace std;
bool C(char c){return isupper(c);}
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(),ptr_fun(C)))!=s.end();++i)
				*i=tolower(*i),s.insert(i,'_');
		cout<<s<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <sstream>	// require stringstream 
#include <cctype>	// require tolower, toupper
//#include <fstream>	// require freopen

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.camelcase", "r", stdin );
	string str, s;
	char type;
	int i;

	while (cin >> str >> type && type != 'X' ){
		char curr_type = 'X';
		if (str.find ('_') != string::npos ){
			curr_type = 'D';
		}else{
			str[0] = toupper(str[0] );
		} // end if
		vector <string> word;

		if (curr_type == 'D'){
			while (str.find('_') != string::npos ){
				str = str.replace (str.find('_'), 1, " " );
			} // end while
			stringstream ss (str );
			s = "";
			while (ss >> s ){
				s[0] = toupper(s[0] );
				word.push_back(s);
			} // end while
		}else{
			s = "";
			s += str[0];
			for (i = 1; i < str.length(); ++i ){
				if (toupper(str[i] ) != str[i] ){
					s += str[i];
				}else{
					word.push_back(s);
					s = "";
					s += str[i];
				} // end if
			} // end for
			word.push_back (s );
		} // end if

		string res = "";

		switch (type ){
			case 'D':
				for (i = 0; i < word.size(); ++i ){
					s = word[i];
					s[0] = tolower(s[0]);
					res += s;
					if (i != word.size() - 1 ){
						res += '_';
					} // end if
				} // end for
				break;
			case 'U':
				for (i = 0; i < word.size(); ++i ){
					res += word[i];
				} // end for
				break;
			case 'L':
				for (i = 0; i < word.size(); ++i ){
					s = word[i];
					s[0] = (i == 0 ? tolower(s[0]) : toupper(s[0]) );
					res += s;
				} // end for
				break;
		} // end switch

		cout << res << endl;			
	} // end loop
		
	return 0;
}