Created
December 25, 2015 07:46
-
-
Save lishunan246/f5908cb9075386138307 to your computer and use it in GitHub Desktop.
1048. 数字加密(20)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include <vector> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
string A, B; | |
cin >> A >> B; | |
vector<char> result; | |
string pattern = "0123456789JQK"; | |
auto jishu = true; | |
do | |
{ | |
int a, b; | |
if (A.empty()) | |
{ | |
a = 0; | |
} | |
else | |
{ | |
a = A.back() - '0'; | |
A.pop_back(); | |
} | |
if (B.empty()) | |
{ | |
b = 0; | |
} | |
else | |
{ | |
b = B.back() - '0'; | |
B.pop_back(); | |
} | |
if (jishu) | |
{ | |
auto t = (a + b) % 13; | |
result.push_back(pattern[t]); | |
} | |
else | |
{ | |
auto t = b - a; | |
if (t < 0) | |
t += 10; | |
result.push_back(pattern[t]); | |
} | |
jishu = !jishu; | |
} | |
while (A.size() != 0 || B.size() != 0); | |
for (auto i = result.crbegin(); i != result.crend(); ++i) | |
cout << *i; | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment