import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//最高支持12位千亿位 可以扩展但没有必要。
public class Number2Chinese {
   public static void main(String [] arg) throws IOException{
    	    //得到键盘输入的值
    	    BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
			String str = buf.readLine();
			Number2Chinese num = new Number2Chinese();
           String str2 = num.change(str);
           System.out.println(num.init(str2));
     }
   public  String init(String str){
    	 str=str.replace('0', '零');
    	 str=str.replace('1', '一');
    	 str=str.replace('2', '二');
    	 str=str.replace('3', '三');
    	 str=str.replace('4', '四');
    	 str=str.replace('5', '五');
    	 str=str.replace('6', '六');
    	 str=str.replace('7', '七');
    	 str=str.replace('8', '八');
    	 str=str.replace('9', '九');
    	 str=str.replace("零零", "零");
    	return str;
     }
   public  static String  sub(String str){//获取每四位的子串
	 StringBuffer stb = new StringBuffer();
	 int leng = str.length();
		 if(leng%4==1){
			 stb.append(str.charAt(0));
		 }
		 if(leng%4==2){
			 stb.append(str.charAt(0)+"拾"+(str.charAt(1)=='0'?"":str.charAt(1)));
		 }
		 if(leng%4==3){
			 stb.append(
				    str.charAt(0)+"佰"
				    +(str.charAt(1)=='0'?(str.charAt(2)=='0'?"":'零'):(str.charAt(1)+"拾"))
				    +(str.charAt(2)=='0'?"":str.charAt(2)));
		 }
	 if(leng%4==0){ 
		 if("0000".equals(str))stb.append("");
		 if(str.charAt(0)=='0'){stb.append( ""+
		   (str.charAt(1)=='0'?(str.charAt(2)=='0'?(str.charAt(3)=='0'?"":'零'):'零'):(str.charAt(1)+"佰"))
			+(str.charAt(2)=='0'?(str.charAt(3)=='0'?"":'零'):(str.charAt(2)+"拾"))
			+(str.charAt(3)=='0'?"":str.charAt(3)));}
		 else stb.append(
			str.charAt(0)+"仟"
			+ (str.charAt(1)=='0'?(str.charAt(2)=='0'?(str.charAt(3)=='0'?"":'零'):'零'):(str.charAt(1)+"佰"))
			+(str.charAt(2)=='0'?(str.charAt(3)=='0'?"":'零'):(str.charAt(2)+"拾"))
			+(str.charAt(3)=='0'?"":str.charAt(3)));
	 }
    	 return stb.toString();
     }
  public  String change(String str){
    	 StringBuffer strbuf = new StringBuffer();
    	 int len = str.length();
    	    if(len>8){
    	    	String a = str.substring(0,len-8);
    	    	String ag = Number2Chinese.sub(a);
    	    	strbuf.append(ag+"亿");
    	    }
    	    if(len>4){
    	    	String b = str.substring(len>8?len-8:0,len-4);
    	    	String bg = Number2Chinese.sub(b);
    	    	if(!"0000".equals(b))strbuf.append(bg+"万");
    	    	else strbuf.append("");
    	    }
    		 String c = str.substring(len-4>0?len-4:0,len);
    		 String cg = Number2Chinese.sub(c);
    		 strbuf.append(cg);
     	 return strbuf.toString();
     }
}












评论
发表评论

您还没有登录,请登录后发表评论

huang_feilong
搜索本博客
最近加入圈子
存档
最新评论