2011-06-17 13:02:05Morris
[JAVA] a008. 中文大寫數字
/**********************************************************************************/
/* Problem: a008 "中文大寫數字" */
/* Language: JAVA */
/* Result: AC (108ms, 5564KB) on ZeroJudge */
/* Author: new1028 at 2011-06-17 10:12:17 */
/**********************************************************************************/
import java.util.Scanner;
public class a008 {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n;
while(cin.hasNext()) {
n = cin.nextInt();
A(n);
}
}
public static void Print(int n) {
char [] c = {'零','壹','貳','參','肆','伍','陸','柒','捌','玖'};
System.out.print(c[n]);
}
public static void A(int x) {
int f = 0;
if(x == 0) {
System.out.println("零");
return ;
}
if(x >= 100000000) {
B(x/100000000, f);
System.out.print("億");
x %= 100000000;
f = 1;
}
if(x >= 10000) {
B(x/10000, f);
System.out.print("萬");
x %= 10000;
f = 1;
}
if(x > 0)
B(x, f);
System.out.println();
return ;
}
public static void B(int x, int f) {
if(f == 1 && x > 0 && x < 1000) {
Print(0);
f = 0;
}
if(x/1000 > 0) {
Print(x/1000);
System.out.print("仟");
x %= 1000;
f = 1;
}
if(f == 1 && x > 0 && x < 100) {
Print(0);
f = 0;
}
if(x/100 > 0) {
Print(x/100);
System.out.print("佰");
x %= 100;
f = 1;
}
if(f == 1 && x > 0 && x < 10) {
Print(0);
f = 0;
}
if(x/10 > 0) {
Print(x/10);
System.out.print("拾");
x %= 10;
f = 1;
}
if(x > 0) Print(x);
}
}
/* Problem: a008 "中文大寫數字" */
/* Language: JAVA */
/* Result: AC (108ms, 5564KB) on ZeroJudge */
/* Author: new1028 at 2011-06-17 10:12:17 */
/**********************************************************************************/
import java.util.Scanner;
public class a008 {
public static void main(String args[]) {
Scanner cin = new Scanner(System.in);
int n;
while(cin.hasNext()) {
n = cin.nextInt();
A(n);
}
}
public static void Print(int n) {
char [] c = {'零','壹','貳','參','肆','伍','陸','柒','捌','玖'};
System.out.print(c[n]);
}
public static void A(int x) {
int f = 0;
if(x == 0) {
System.out.println("零");
return ;
}
if(x >= 100000000) {
B(x/100000000, f);
System.out.print("億");
x %= 100000000;
f = 1;
}
if(x >= 10000) {
B(x/10000, f);
System.out.print("萬");
x %= 10000;
f = 1;
}
if(x > 0)
B(x, f);
System.out.println();
return ;
}
public static void B(int x, int f) {
if(f == 1 && x > 0 && x < 1000) {
Print(0);
f = 0;
}
if(x/1000 > 0) {
Print(x/1000);
System.out.print("仟");
x %= 1000;
f = 1;
}
if(f == 1 && x > 0 && x < 100) {
Print(0);
f = 0;
}
if(x/100 > 0) {
Print(x/100);
System.out.print("佰");
x %= 100;
f = 1;
}
if(f == 1 && x > 0 && x < 10) {
Print(0);
f = 0;
}
if(x/10 > 0) {
Print(x/10);
System.out.print("拾");
x %= 10;
f = 1;
}
if(x > 0) Print(x);
}
}
下一篇:[JAVA] a009. 解碼器
Andy
2013-03-21 16:01:57
好像沒有陣列。
原來是我看錯了