1048 数字加密(20 分)

#include
#include
#include
#include
using namespace std;
string a, b;
vectorans;
char cc[3] = { 'J','Q','K' };
int main()
{
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    while (a.size() < b.size())a += '0';
    while (b.size() < a.size())b += '0';
    for (int i = 0; i < a.length(); i++)
    {
        if (i % 2 == 0)
        {
            int sum=(a[i]-'0'+b[i]-'0')%13;
            if (sum < 10)ans.push_back(sum + '0');
            else ans.push_back(cc[sum - 10]);
        }
        else
        {
            int sum = b[i] - '0' - (a[i] - '0');
            if (sum < 0)sum += 10;
            ans.push_back(sum + '0');
        }
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++)cout << ans[i];
    return 0;
}

你可能感兴趣的:(1048 数字加密(20 分))