生活随笔
收集整理的這篇文章主要介紹了
【PAT乙级】1048 数字加密 (20 分)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目地址
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std
;
string s
[15]={"0","1","2","3","4","5","6","7","8","9","J","Q","K"};
int main(void)
{string a
,b
; 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';string ans
;for(int i
=0;i
<b
.size();i
++){if(i
%2){int t
=b
[i
]-a
[i
];if(t
<0) t
+=10;ans
+=s
[t
];}else ans
+=s
[(b
[i
]-'0'+a
[i
]-'0')%13];}reverse(ans
.begin(),ans
.end());cout
<<ans
;
}
#include<bits/stdc++.h>
using namespace std
;
string a
,b
,ans
;
string s
[15]={"0","1","2","3","4","5","6","7","8","9","J","Q","K"};
int main(void)
{cin
>>a
>>b
;reverse(a
.begin(),a
.end());reverse(b
.begin(),b
.end());while(b
.size()<a
.size()) b
+="0";while(a
.size()<b
.size()) a
+="0";for(int i
=0;i
<b
.size();i
++){if(i
&1) ans
+=s
[(b
[i
]-a
[i
]+10)%10];else ans
+=s
[(a
[i
]-'0'+b
[i
]-'0')%13];}reverse(ans
.begin(),ans
.end());cout
<<ans
;return 0;
}
總結(jié)
以上是生活随笔為你收集整理的【PAT乙级】1048 数字加密 (20 分)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。