1048(16)

两个答案错误

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc=new Scanner(System.in);
        String astr=sc.next();
        String bstr=sc.next();
        String[] a=astr.split("");
        String[] b=bstr.split("");
        String[] c=new String[b.length];

        //a从最后一位到第一位和b进行判断,正常来讲
        if (a.length%2==1){//a有奇数位
            int j=b.length;
            for (int i=a.length-1;i>=0;i--){//i初始值是偶数
                for (j=j-1;j>=0;j--){
                    if (j<=b.length-1&&j>=b.length-a.length){
                        if (i%2==0){//奇数位
                            int temp=(Integer.parseInt(a[i])+Integer.parseInt(b[j]))%13;
                            if (temp>=0&&temp<=9){
                                c[j]=temp+"";
                            }else if (temp==10){
                                c[j]="J";
                            }else if (temp==11){
                                c[j]="Q";
                            }
                            else if (temp==12){
                                c[j]="K";
                            }
                            break;
                        }
                        else if (i%2==1){
                            int temp1=Integer.parseInt(b[j])-Integer.parseInt(a[i]);
                            if (temp1>=0){
                                c[j]=temp1+"";
                            }else{
                                temp1=temp1+10;
                                c[j]=temp1+"";
                            }
                            break;
                        }
                    }

                }
            }
            for (int i=0;i<b.length-a.length;i++){
                c[i]=b[i];
            }
        }else{
            int k=b.length;
            for (int i=a.length-1;i>=0;i--){//i初始值是奇数
                for (k=k-1;k>=0;k--){
                    if (i%2==1){//奇数位
                        int temp=(Integer.parseInt(a[i])+Integer.parseInt(b[k]))%13;
                        if (temp>=0&&temp<=9){
                            c[k]=temp+"";
                        }else if (temp==10){
                            c[k]="J";
                        }else if (temp==11){
                            c[k]="Q";
                        }
                        else if (temp==12){
                            c[k]="K";
                        }
                        break;
                    }
                    else{
                        int temp1=Integer.parseInt(b[k])-Integer.parseInt(a[i]);
                        if (temp1>=0){
                            c[k]=temp1+"";
                        }else{
                            temp1=temp1+10;
                            c[k]=temp1+"";
                        }
                        break;
                    }
                }
            }
            for (int i=0;i<b.length-a.length;i++){
                c[i]=b[i];
            }
        }
        for (int i=0;i<c.length;i++){
            if (i==c.length-1){
                System.out.print(c[i]);
            }else
            System.out.print(c[i]);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值