The title

This problem requires the implementation of a digital encryption method. Firstly, A positive integer A is fixed for encryption. For any positive integer B, the following operations are performed on every 1 digit of the positive integer B and the corresponding digits of A: For odd digits, the corresponding digits are added and mod 13 — J represents 10, Q represents 11 and K represents 12. The dual digit is subtracted from the number of B from the number of A. If the result is negative, add 10. Let’s make the ones place the first place.

Input format

Input gives A and B in sequence on A line, which are positive integers of up to 100 characters separated by Spaces.

The output format

Print the encrypted result on one line.

Train of thought

This problem requires some familiarity with string manipulation. First we need a string s: string s = {“0123456789JQK”}; “To add to the output answer string res. The odd and even bits are processed separately by traversal. Note that since the traversal starts at 0, the odd and even bits are reversed. Because they’re saying, let’s make the ones place the first place. Let’s make the ones place the first place. Let’s make the ones place the first place. , so the input strings a and b should be reversed, and the output of res should also be reversed. As can be seen from the example, the number of digits of A and B may not be the same, so we need to complement the one with fewer digits, by adding 0.

//foreverking
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;

/* J represents 10, Q represents 11, and K represents 12 odd digits. Mod 13 by subtracting the number of A from the number of B. If the result is negative, add 10 */

string a,b;// Use string to store 100 bits
string s = {"0123456789JQK"};
string res;
char ch;

int main(){
    cin >> a >> b;
    // reverse transpose the bits
    int lenb = b .size(),lena = a.size();// According to the example, a and B do not match, so we need to complement 0
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    if (lena > lenb)
        b.append(lena - lenb, '0');
    // else
    // a.append(lenb - lena, '0');
    for(int i = 0; i < a.size(); i++){
        int temp;
        if(i % 2= =0)/ / odd
            temp = (a[i] - '0' + b[i] - '0') % 13;
        else{/ / even
            temp = b[i] - a[i];
            if(temp < 0)
                temp += 10;
        }
        res += s[temp];
    }
    // for (int i = res.length() - 1; i >= 0; i--)
    // cout << res[i];
    reverse(res.begin(),res.end());
    cout << res << endl;
    return 0;
}
//3695Q8118
/ / 1234567 368782971
Copy the code

Topic link