首页
学习
活动
专区
圈层
工具
发布
30 篇文章
1
PAT (Basic Level) Practice (中文)1054 求平均值 (20 分)
2
PAT (Basic Level) Practice (中文)1051 复数乘法 (15 分)
3
PAT (Basic Level) Practice (中文)1050 螺旋矩阵 (25 分)
4
PAT (Basic Level) Practice (中文)1046 划拳 (15 分)
5
PAT (Basic Level) Practice (中文)1045 快速排序 (25 分)
6
PAT (Basic Level) Practice (中文)1047 编程团体赛 (20 分)
7
PAT (Basic Level) Practice (中文)1043 输出PATest (20 分)
8
PAT (Basic Level) Practice (中文)1042 字符统计 (20 分)
9
PAT (Basic Level) Practice (中文)1040 有几个PAT (25 分)
10
PAT (Basic Level) Practice (中文)1038 统计同成绩学生 (20 分)
11
PAT (Basic Level) Practice (中文)1036 跟奥巴马一起编程 (15 分)
12
PAT (Basic Level) Practice (中文)1034 有理数四则运算 (20 分)
13
PAT (Basic Level) Practice (中文)1032 挖掘机技术哪家强 (20 分)
14
PAT (Basic Level) Practice (中文)1031 查验身份证 (15 分)
15
PAT (Basic Level) Practice (中文)1030 完美数列 (25 分)
16
PAT (Basic Level) Practice (中文)1029 旧键盘 (20 分)
17
PAT (Basic Level) Practice (中文)1028 人口普查 (20 分)
18
PAT (Basic Level) Practice (中文)1027 打印沙漏 (20 分)
19
PAT (Basic Level) Practice (中文)1025 反转链表 (25 分)
20
PAT (Basic Level) Practice (中文)1053 住房空置率 (20 分)
21
PAT (Basic Level) Practice (中文)1024 科学计数法 (20 分)
22
PAT (Basic Level) Practice (中文)1022 D进制的A+B (20 分)
23
PAT (Basic Level) Practice (中文)1049 数列的片段和 (20 分)
24
PAT (Basic Level) Practice (中文)1021 个位数统计 (15 分)
25
PAT (Basic Level) Practice (中文)1048 数字加密 (20 分)
26
PAT (Basic Level) Practice (中文)1019 数字黑洞 (20 分)
27
PAT (Basic Level) Practice (中文)1017 A除以B (20 分)
28
PAT (Basic Level) Practice (中文)1016 部分A+B (15 分)
29
PAT (Basic Level) Practice (中文)1015 德才论 (25 分)
30
PAT (Basic Level) Practice (中文)1014 福尔摩斯的约会 (20 分)

PAT (Basic Level) Practice (中文)1048 数字加密 (20 分)

1048 数字加密 (20 分)

本题要求实现一种数字加密方法。首先固定一个加密用正整数 A,对任一正整数 B,将其每 1 位数字与 A 的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对 13 取余——这里用 J 代表 10、Q 代表 11、K 代表 12;对偶数位,用 B 的数字减去 A 的数字,若结果为负数,则再加 10。这里令个位为第 1 位。

输入格式:

输入在一行中依次给出 A 和 B,均为不超过 100 位的正整数,其间以空格分隔。

输出格式:

在一行中输出加密后的结果。

输入样例:

代码语言:javascript
复制
1234567 368782971

输出样例:

代码语言:javascript
复制
3695Q8118

这题本来是一道简单的模拟题,但是问题在于一些特殊情况的出理:数A和数B,要考虑A的位数与B的位数不等的情况,这里要注意如果数位不等都补零,比方说样例中A位数比B少对应B的3和6A就是0和0~,注意进位不是简单的十进制,大于十的部分要用字母代替~

代码语言:javascript
复制
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
char a[1005],b[1005],c[1005];
ll tot;
int main()
{
    cin>>a>>b;
    ll cnt=0;
    rg i,j;
    //cout<<a[0]<<endl;
    for(i=strlen(b)-1, j=strlen(a)-1;j>=0&&i>=0;i--,j--)
    {
        //cout<<i<<" "<<j<<" "<<cnt<<endl;
        cnt++;
        if(cnt%2)
        {
            ll k=(b[i]-48+a[j]-48)%13;
            if(k==10)c[++tot]='J';
            if(k==11)c[++tot]='Q';
            if(k==12)c[++tot]='K';
            if(k>=0&&k<=9)c[++tot]=48+k;
        }
        else
        {
            ll k=b[i]-a[j];
            if(k<0)k+=10;
            c[++tot]=48+k;
        }
    }
    //cout<<i<<" "<<j<<" "<<cnt<<endl;
    if(i>=0)
    for(rg k=i;k>=0;k--)
    {
        c[++tot]=b[k];
    }
    if(j>=0)
    for(rg k=j;k>=0;k--)
    {
        //cout<<tot<<endl;
        cnt++;
        if(cnt%2)c[++tot]=a[k];
        else
        {
            if(a[k]!='0')
            {
                c[++tot]=106-a[k];
            }
            else c[++tot]=a[k];
        }
    }
    for(rg i=tot;i>=1;i--)cout<<c[i];
   	return 0;
}
下一篇
举报
领券