PAT.1048 数字加密

1.当B的长度大于A时,直接将B前面的复制过去


2.当A的长度大于B时,B前面要补0,并且要判断奇数位偶数位


3.当A为10000,B为1时,要判断为0时应该打印0,最后打印10001,之前没判断直接A的那位数变负数再加10,所以会出问题


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
	char a[105],b[105],c[105];
	cin >> a >> b;
	int i = strlen(a)-1;
	int j = strlen(b)-1;
	//cout << i << j<<endl; 
	int count=0;
	
	while(i>=0&&j>=0)
	{
		if(count % 2 == 0)
		{
			
			int x = (a[i]-'0' + b[j]-'0')%13;
		//	cout << " x " <<x << endl;
			switch(x)
			{
				case 10:c[count++] = 'J';
						break;
				case 11:c[count++] = 'Q';
						break;
				case 12:c[count++] = 'K';
						break;
				default:c[count++] = x+'0'; 
						break;
			}
			i--;
			j--;
	//		cout << "count "<<count<<endl;
		}
		else
		{
			
			int y;
			y = (b[j]-'0') - (a[i] - '0');
			
			if(y<0)
				y += 10;
		//	cout << " " << y << endl;	
			c[count++] = y + '0'; 
			i--;
			j--; 
		}
		
	}
	
	while(j>=0)
	{
		c[count++] = b[j];
		j--; 
	}

	while(i>=0)
	{
		if(count % 2 == 0)
		{
			c[count++] = a[i];
			
		}
		else
		{
			if(a[i]=='0')
				c[count++] = a[i];
			else
			c[count++] = -(a[i]-'0')+10+'0';	
		}
			i--;
		
		
	}
	
	for(i=strlen(c)-1;i>=0;i--)
		cout << c[i];
		cout << endl;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值