首页 > 其他 > 详细

J 计算A+B 大数

时间:2021-02-25 11:37:09      阅读:32      评论:0      收藏:0      [点我收藏+]

https://ac.nowcoder.com/acm/contest/4462/J

技术分享图片

 

 有前导0是可以的

 

 1 import java.math.BigInteger;
 2 import java.util.Scanner;
 3 
 4 public class Main {
 5     public static  void solve(String m){
 6         char p[]=m.toCharArray();
 7         for(int i=0;i<m.length();i++){
 8             if((p[i]<0||p[i]>9)&&p[i]!=+) {
 9                 System.out.println("skipped");
10                 return;
11             }
12         }
13         if(p[0]==+||p[m.length()-1]==+){
14             System.out.println("skipped");
15             return;
16         }
17         int index=0;
18         int cnt=0;
19         for(int i=1;i<m.length()-1;i++){
20             if(p[i]==+){
21                 cnt++;
22                 index=i;
23             }
24         }
25         if(cnt==0||cnt>1){
26             System.out.println("skipped");
27             return;
28         }
29         BigInteger a= new BigInteger(m.substring(0,index));
30         BigInteger b= new BigInteger(m.substring(index+1));
31         a=a.add(b);
32         String c=a+"";
33         System.out.println(c);
34  
35     }
36     public static void main(String[] args) {
37         Scanner input = new Scanner(System.in);
38         int n = input.nextInt();
39         for(int i=1;i<=n;i++){
40             String m = input.next();
41             solve(m);
42         }
43 
44     }
45 }

 

J 计算A+B 大数

原文:https://www.cnblogs.com/pangbi/p/14445547.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!