B1048 数字加密

15/20

#include<bits/stdc++.h>
using namespace std;
stack<int> s;
char a[3]={'J','Q','K'};
int main(){
    long long A,B;
    cin>>A>>B;
    int i=1;
    while(A>0&&B>0){
        if(i%2==1){
            s.push((A%10+B%10)%13);
        }else{
            int x=B%10-A%10;
            if(x<0)x+=10;
            s.push(x);
        }
        A/=10;B/=10;
        i++;
    }
    if(A>0)cout<<A;
    if(B>0)cout<<B;
    while(!s.empty()){
        if(s.top()<=9)cout<<s.top();
        else cout<<a[s.top()-10];
        s.pop();
    }
    return 0;
}

后来觉得题目理解有问题,B的每一位数字都要处理。
15/20

#include<bits/stdc++.h>
using namespace std;
stack<int> s;
char a[3]={'J','Q','K'};
int main(){
    long long A,B;
    cin>>A>>B;
    int i=1;
    while(B>0){
        if(i%2==1){
            s.push((A%10+B%10)%13);
        }else{
            int x=B%10-A%10;
            if(x<0)x+=10;
            s.push(x);
        }
        if(A>0)A/=10;
        B/=10;
        i++;
    }
    while(!s.empty()){
        if(s.top()<=9)cout<<s.top();
        else cout<<a[s.top()-10];
        s.pop();
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/MarkKobs-blog/p/10557854.html