# 求A的B次方末尾三位数

## 示例

输入：2000,1111



## AC代码

import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int base, exp;
String[] tmp;
tmp = scanner.nextLine().split(",");
base = Integer.parseInt(tmp[0]);
exp = Integer.parseInt(tmp[1]);
long res = base%1000;
for(int i = 1; i < exp; i++){
res = (res * base) % 1000;
}
System.out.printf("\"%03d\"",res);
}
}


# 中文数字转为阿拉伯数字

## 示例

一百六十三
163


## AC代码

class Solution{
public String convert(String number){
String[] numbers = new String[3];
if(number.split("亿").length == 1){
if(number.charAt(number.length()-1) == '亿'){
// 尾部是亿的情况
numbers[0] = number.split("亿")[0];
numbers[1] = "";
numbers[2] = "";
}else{
// 不含亿的情况
numbers[0] = "";
numbers[1] = number;
numbers[2] = "";
}
}else{
// 亿在中间的情况
numbers[0] = number.split("亿")[0];
numbers[1] = number.split("亿")[1];
numbers[2] = "";
}
if(numbers[1].split("万").length == 1){
if(numbers[1].length()>0 && numbers[1].charAt(numbers[1].length()-1) == '万'){
// 如果万是结尾
numbers[1] = numbers[1].split("万")[0];
numbers[2] = "";
}else if(numbers[1].length() > 0){
// 不含万的情况
numbers[2] = numbers[1];
numbers[1] = "";
}else{
// numbers[1]为空的情况
numbers[1] = "";
numbers[2] = "";
}
}
System.out.println(Arrays.toString(numbers));
Map<Character,Integer> map = new HashMap<>();
map.put('一',1);
map.put('二',2);
map.put('三',3);
map.put('四',4);
map.put('五',5);
map.put('六',6);
map.put('七',7);
map.put('八',8);
map.put('九',9);
map.put('零',0);
map.put('十',10);
map.put('百',100);
map.put('千',1000);
map.put('万',10000);
map.put('亿',100000000);
long res = 0;
for(int i = 0; i < 3; i++){
if(numbers[i].equals("")){
continue;
}
long curRes = 0;
int j = 0;
while(j < numbers[i].length()){
if(numbers[i].charAt(j) == '零'){
j++;
}else if(j < numbers[i].length()-1){
curRes += map.get(numbers[i].charAt(j))*map.get(numbers[i].charAt(j+1));
j += 2;
}else{
curRes += map.get(numbers[i].charAt(j));
j++;
}
}
if(i == 0){
curRes *= map.get('亿');
}else if(i == 1){
curRes *= map.get('万');
}
res += curRes;
}
return String.valueOf(res);
}
}


©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客