This problem required to achieve a digital encryption method. First, encrypted with a fixed positive integer A, for any positive integer B, and the numbers on each of positions corresponding to 1-bit digital to A following operation: After an odd bit, the corresponding bit of the digital sum modulo 13 - - 10 used here representative of J, representative of Q 11, K 12 represents; on even bit, with the number B minus the number of a, if the result is negative, then add 10. Here a bit to make the first one.
Input formats:
Given in one row sequentially input A and B, no more than 100 are positive integers, separated by a space therebetween.
Output formats:
The output encrypted in a row.
Sample input:
1234567 368782971
Sample output:
3695Q8118
Author: CHEN, Yue
Unit: Zhejiang University
Time limit: 400 ms
Memory Limit: 64 MB
#include<iostream> #include<stack> using namespace std; int main() { string s,s2; cin>>s>>s2; stack<int> sta1,sta2; stack<char> res; int tmp1,tmp2,tmpRes; for(int i=0;i<s.length();i++){ sta1.push(s[i]-'0'); } for(int i=0;i<s2.length();i++){ sta2.push(s2[i]-'0'); } bool isOdd=true; while(!sta1.empty()||!sta2.empty()){ //取数值 if(!sta1.empty()) { tmp1=sta1.top(); sta1.pop(); }else{ tmp1=0; } if(!sta2.empty()) { tmp2=sta2.top(); sta2.pop(); }else{ tmp2=0; } //奇偶处理数据 if(isOdd){ tmpRes=(tmp1+tmp2)%13; switch(tmpRes){ case 10:res.push('J');break; case 11:res.push('Q');break; case 12:res.push('K');break; default:res.push(tmpRes+'0');break; } }else{ tmpRes=tmp2-tmp1; if(tmpRes<0)tmpRes+=10; res.push(tmpRes+'0'); } isOdd=!isOdd; } //output while(!res.empty()){ cout<<res.top(); res.pop(); } system("pause"); return 0; }