zoukankan      html  css  js  c++  java
  • 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]='';
    50             for(int i=0;i<w;i++)
    51             {
    52                 reans[i]=ans[w-1-i];
    53             }
    54             reans[w]='';
    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

  • 相关阅读:
    python_元素定位
    python_html_初识
    python_selenium_初识
    python_jenkins_集成
    python_正则表达式_re
    python_接口关联处理与pymysql中commit
    python_json与pymsql模块
    python_接口请求requests模块
    Codeforces Round #656 (Div. 3) D. a-Good String
    Codeforces Round #656 (Div. 3) C. Make It Good
  • 原文地址:https://www.cnblogs.com/wsruning/p/4705747.html
Copyright © 2011-2022 走看看