Java大数 字符串处理 HDU2100

 1 import java.math.*;
 2 import java.util.*;
 3 
 4 public class Main
 5 {
 6     static String arr1;
 7     static String arr2;;
 8     static char[] ans=new char [200];
 9     static char[] reans=new char [200];
10     static BigInteger c=new BigInteger("26");
11     public static void main(String[] args)
12     {
13         Scanner cin=new Scanner(System.in);
14         while(cin.hasNext())
15         {
16             arr1=cin.next();
17             arr2=cin.next();
18             int len1=arr1.length();
19             int len2=arr2.length();
20             BigInteger a=BigInteger.ZERO;
21             BigInteger b=BigInteger.ZERO;
22             for(int i=0;i<len1-1;i++)
23             {
24                 char item=arr1.charAt(i);
25                 a=a.add(BigInteger.valueOf((item-'A')));
26                 a=a.multiply(c);
27             }
28             char item1=arr1.charAt(len1-1);
29             a=a.add(BigInteger.valueOf((item1-'A')));
30             for(int i=0;i<len2-1;i++)
31             {
32                 char item=arr2.charAt(i);
33                 b=b.add(BigInteger.valueOf((item-'A')));
34                 b=b.multiply(c);
35             }
36             char item2=arr2.charAt(len2-1);
37             b=b.add(BigInteger.valueOf((item2-'A')));
38             a=a.add(b);
39             int w=0;
40             while(a.compareTo(BigInteger.ZERO)>0)
41             {
42                 int x=a.remainder(c).intValue();
43                 a=a.divide(c);
44                 char cc='A';
45                 int tt=(int)cc;
46                 ans[w]=(char)(tt+x);
47                 w++;
48             }
49             ans[w]='\0';
50             for(int i=0;i<w;i++)
51             {
52                 reans[i]=ans[w-1-i];
53             }
54             reans[w]='\0';
55             for(int i=0;i<w;i++)
56             {
57                 System.out.print(reans[i]);
58             }
59             System.out.println();
60         }
61     }
62 }
View Code

char item=arr1.charAt(i);  //获取String中的特定位置

a.remainder(b);        //a%b

转载于:https://www.cnblogs.com/wsruning/p/4705747.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值