/**
1. 怎么将数字对应到中文上, 一个思路是按单位对应, 分治处理
1.1 dfs 顺序: 确定单位后, 递归处理单位前的值与单位后的值
1.2 dfs 状态: 待处理的数字
1.3 剪枝: ~
2. 中文习惯, 如果单位不连续中间加"零":
2.1 亿后面必须是千, 否则加零; 万后面必须是千, 否则加零
2.2 其他单位在"万"后面时, "千"后面必须是"百", "百"后面必须是"十", 否则加"零"
2.3 其他单位在"万"前面时, 如果存在个位且"万"前面的单位不是"十", 加零
*/
import java.util.*;
class Main{
final private int[] units = {10, 100, 1000, 10000, 100000000};
final private Map<Integer, String> toCN = init();
final private Map<Character, String> inv = initInv();
void run(){
int num = jin.nextInt();
String cn = parseChinese(num);
System.out.println(cn);
}
private String parseChinese(int num){
boolean neg = false;
if (num < 0) {
neg = true;
num = -num;
}
String chinese = dfs(num);
String result = fix(chinese, num);
return neg ? "Fu " + result : result;
}
public String dfs(int num){
int unit = units[upperBound(num)];
if (num < unit) return toCN.get(num);
int head = num / unit, tail = num % unit;;
if (tail == 0) return dfs(head) + " " + toCN.get(unit);
return dfs(head) + " " + toCN.get(unit) + " " + dfs(tail);
}
public int upperBound(int num){
int l = 0, r = units.length - 1;
while (l < r){
int mid = l + r + 1>> 1;
if (num >= units[mid]) l = mid;
else r = mid - 1;
}
return l;
}
String fix(String cn, int num){
char prev = num % 10 == 0 ? ' ' : 'G';
StringBuilder buffer = new StringBuilder();
for (int i = cn.length()-1 ; i >= 0; i--){
char c = cn.charAt(i);
boolean need = false;
if ('A' <= c && c <= 'Z'){
need =needLing(prev, c, num);
prev = c;
}
if (!need) {
buffer.append(c);
continue;
}
String invWord = inv.get(prev);
buffer.setLength(Math.max(buffer.length() - invWord.length(), 0));
buffer.append(" gnil ");
buffer.append(invWord);
}
return buffer.reverse().toString();
}
boolean needLing(char prev, char c, int num){
boolean rule1 = (c == 'S' && prev != 'W' ) ||(c == 'Y' && prev != 'Q') || (c == 'W' && prev != 'Q') || (c == 'Q' && prev != 'B') || (c == 'B' && prev != 'S');
boolean rule2 = (prev == 'G' && c != 'S') || (prev != 'G' && prev != ' ' && rule1);
boolean rule3 = (prev == 'W' && num / 10000 % 10 == 0);
return rule2 && !rule3;
}
private Map<Character, String> initInv(){
Map<Character, String> inv = new HashMap<>();
inv.put('Y', "iY");
inv.put('W', "naW");
inv.put('Q', "naiQ");
inv.put('B', "iaB");
inv.put('S', "ihS");
return inv;
}
private Map<Integer, String> init(){
Map<Integer, String> toCN = new HashMap<>();
toCN.put(0, "ling");
toCN.put(1, "yi");
toCN.put(2, "er");
toCN.put(3, "san");
toCN.put(4, "si");
toCN.put(5, "wu");
toCN.put(6, "liu");
toCN.put(7, "qi");
toCN.put(8, "ba");
toCN.put(9, "jiu");
toCN.put(10, "Shi");
toCN.put(100, "Bai");
toCN.put(1000, "Qian");
toCN.put(10000, "Wan");
toCN.put(100000000, "Yi");
return toCN;
}
private Scanner jin = new Scanner(System.in);
public static void main(String[] main){new Main().run();}
}