PAT 乙级 1048 数字加密 (20分)

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;
	string result;
	while (a.length() != b.length()) 
	{
		if (a.length() > b.length())
			b = '0' + b;
		else
			a = '0'+a;
	}
	int res = 0, res1 = 0;
	int count = 0;
	for (int i = a.length()-1; i >=0; i--)
	{
		count=count+1;
		switch (count%2)
		{
		case 0:
			 res = (b[i]-'0')-(a[i]-'0');
			if (res < 0)
				result = result + to_string(res + 10);
			else
				result = result + to_string(res);
			break;
		case 1:
			 res1 = ((b[i] - '0') + (a[i] - '0')) % 13;
			if (res1 >= 0 && res1 < 10)
				result = result + to_string(res1);
			if(res1==10)
				result = result + 'J';
			if (res1 == 11)
				result = result + 'Q';
			if (res1 == 12)
				result = result + 'K';
			break;
		default:
			break;
		}
	}
	reverse(result.begin(),result.end());
	cout << result << endl;
	system("pause");
	return 0;
}
上一篇:mac照片尺寸大小批量压缩转换器Photo Size Changer


下一篇:Win7 下硬盘安装Linux Mint 17