【B1048/字符处理】数字加密

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 110;
int main() {
	int a, b;
	int A[maxn] = { 0 }, B[maxn] = { 0 };
	//char C[maxn] = { 0 };   字符数组不初始化会输出 烫烫烫...
	string C;
	cin >> a >> b;
	int m = 0,n = 0;
	/*while (a != 0 || b != 0) {	//这里k累加了两次
		A[k++] = a % 10;
		B[k++] = b % 10;
		a /= 10;
		b /= 10;
		cout << A[k-1]<<" ";
	}*/
	while (a != 0) {
		A[m++] = a % 10;
		a /= 10;
	}
	while (b != 0) {
		B[n++] = b % 10;
		b /= 10;
	}
	int k = max(m, n);
	int i = 0, j = 0;
	while (i < k && j < k) {
		if (i % 2 == 0) {  //奇数位的处理
			int temp = (A[i] + B[i])%13;
			if (temp == 10)
				C += 'J';	//!!string C只是定义了C,但是是个空字符串,不能用数组下标访问,故C[i]='J'是错误的,应该用+来拼接字符串
			else if (temp == 11)
				C += 'Q';
			else if (temp == 12)
				C += 'K';
			else
				C += temp - 0 + '0';
		}
		else {
			int temp = B[i] - A[i];
			if (temp < 0)
				temp += 10;
			C += temp - 0 + '0';
		}
		i++;
		j++;
	}
	while (i < k)
		C += A[i++] - 0 + '0' ;
	while (j < k)
		C += A[j++] - 0 + '0';
	for (int i = C.length() - 1; i >= 0; i--)
		cout << C[i];
	system("pause");
	return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值