当前位置:网站首页>Arabic numerals to Chinese
Arabic numerals to Chinese
2022-07-19 06:41:00 【hello,world_ yzs】
Cat's eye interview questions 
error :
1.String[] Array fixed , Back res.add error , use arraylist perhaps vector Variable array
2. The number of zeros is not considered
1001 It should be onethousand and one , Code output 10011
1000 It should be a thousand , Code output 1000
The right code , as follows :
public class NumtoHanzi {
public static String convertHanzi(String a) {
String [] uniform = {
" zero "," Ten "," hundred "," thousand "};
String [] hanzi = {
" zero "," One "," Two "," 3、 ... and "," Four "," 5、 ... and "," 6、 ... and "," 7、 ... and "," 8、 ... and "," Nine "};
if(a == null)
return null;
int len = a.length();
int index = len - 1;
if(a == "10")
return " Ten ";
int[] digit = new int[a.length()];
int i = 0;
String res = " ";
while(index >= 0) {
int num = Integer.parseInt(String.valueOf(a.charAt(index)));
digit[i] = num;
index--;
i++;
}
for(int j = len - 1; j >= 0; j--) {
if(digit[j] != 0) {
res += hanzi[digit[j]];
if(j != 0) {
res += uniform[j];
}
}else {
while(j >=0 && digit[j] == 0) {
j--;
}
if(j == -1)
break;// All are zero
// Zero connection is blocked
res += uniform[0];
j++;// The loop itself has to j--;
}
}
return res;
}
public static void main(String[] args) {
System.out.println(convertHanzi("1011"));
}
}
Ideas :
First, store the number in reverse order ,1234 Save as 4321.
And then to 4321, Subscript 3 The corresponding number 1, add uniform The corresponding subscript 3 The connective thousand , When subscript is 0, No connectives .
Dealing with zero , Go straight to zero until the end , Then there is no zero , Such as 1000 perhaps 1100.
The zero connection is blocked , Then add “ zero ”, Such as 1001,1011
边栏推荐
- Experiment class II and object definition initialization
- Leetcode tree
- Query of database (II)
- Operation of documents in index library
- Bottom up and top-down attention: different processes and overlapping nervous systems 2014sci
- 《PyTorch深度学习实践》-B站 刘二大人-day7
- 吴恩达机器学习第10-11章
- Seachest utilities tool enables your hard disk to consume less power and live longer
- Spot detection record
- 山西省第二届网络安全技能大赛(企业组)部分赛题WP(三)
猜你喜欢

DSL realizes automatic completion query

通過VOR深度估計解决三維注視交互中的目標模糊問題

剑指offer刷题

吴恩达机器学习第12-13章

三维凝视估计,没有明确的个人校准2018

机器人缝合手势识别和分类
![[force buckle] design cycle queue](/img/77/f1da62b302eaf16a271512527b096f.png)
[force buckle] design cycle queue

Solution: unable to load file c:\program files\ Because running scripts is forbidden on this system

Read pictures and convert them to show different color spaces

《PyTorch深度学习实践》-B站 刘二大人-day6
随机推荐
Antd is not defined
Part of the second Shanxi Network Security Skills Competition (Enterprise Group) WP (III)
網絡中的一些基本概念
数据库的查询(二)
C language specifies how many days to display from the date
Some basic concepts in network
Using VOR depth estimation to solve the problem of target ambiguity in three-dimensional gaze interaction
大龄程序员都去哪了?
EOG based eye movement detection and gaze estimation for an asynchronous virtual keyboard
Preorder traversal of binary tree
翻转链表
无80和443端口下申请域名SSL证书(适用于 acme.sh 和 certbot)
From entering URL to displaying page
Convert PNG with transparency to C array
Busybox 1.21.1 has udpsvd function, which can be compiled successfully without interfering with the local busybox method
Acwing daily question three thousand five hundred and eleven
[force buckle] bracket matching
LeetCode树
Design and implementation of a gesture control system for tablet computer based on gaze
SalGaze:使用视觉显著性的个性化注视估计