指数计算
题目:
7 ^ 2020 mod 1921,其中 A mod B 表示 A 除以 B 的余数
思路:
这应该是很简单的一道题了,但是再写一遍就是觉得大数类考到的可能性还是很大的
代码:
import java.math.BigInteger;
public class 指数计算 {
public static void main(String[] args) {
BigInteger a=new BigInteger("7");
BigInteger b=new BigInteger("1921");
BigInteger c=a.pow(2020).remainder(b);
System.out.println(c);
}
}
解密
题目:
根据字母加密规则,将加密后的字符串解密
思路:
利用HashMap的键值存储方式,将加密的对应字符存储为键,然后输出值
代码:
import java.util.HashMap;
import java.util.Scanner;
public class 解密 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
HashMap<Character,Character> hashMap=new HashMap<>();
for (int i = 0; i < 52; i++) {
char a=sc.next().trim().charAt(0);
//sc.next()返回一个String类型对象
//.trim()去掉空格
//.charAt()返回一