PAT乙级1048

1048. 数字加密(20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

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

输入格式:

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

输出格式:

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

输入样例:
1234567 368782971
输出样例:

3695Q8118

#include<stdio.h>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

int main()
{
	string s1, s2,s3,s4;
	cin >> s1 >> s2;
	int len1 = s1.size();
	int len2 = s2.size(); int temp; char temp1,temp2;
	for (int i = 0; i < max(len1,len2); i++)
	{
		if (i > len1 - 1)
		{
			temp1 = '0';//这里是坑
		}
		else
			temp1 = s1[len1 - 1 - i];
		if (i > len2 - 1)
		{
			temp2 = '0';//这里是坑
		}
		else
			temp2 = s2[len2 - 1 - i];
		if (i % 2 == 0)
		{
			temp = (temp2 - '0' + temp1 - '0') % 13;
			if (temp < 10)
				temp2 = temp + '0';
			else if(temp==10)
				temp2 = 'J';
			else if (temp == 11)
				temp2 = 'Q';
			else if (temp == 12)
				temp2 = 'K';
		}
		else
		{
			temp = temp2 - temp1;
			if (temp < 0)
				temp2 = temp + 10 + '0';
			else
				temp2 = temp +'0';
		}
		s4 = temp2;
		s3.insert(0,s4);
	}
	cout << s3;
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值