PAT乙级1048 数字加密 (20 分)
Posted 辉小歌
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT乙级1048 数字加密 (20 分)相关的知识,希望对你有一定的参考价值。
#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;
string ans;
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)&1)
{
int t=b[i]-'0'+a[i]-'0';
ans+=s[t%13];
}
else
{
int t=(b[i]-'0')-(a[i]-'0');
if(t>=0) ans+=s[t];
else ans+=s[t+10];
}
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
return 0;
}
#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;
}
以上是关于PAT乙级1048 数字加密 (20 分)的主要内容,如果未能解决你的问题,请参考以下文章