总结:
反转两次;
反转时,i=0时,i<len/2,切记没有等于号;
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
const int maxn = 110;
char A[maxn], B[maxn], ans[maxn] = { 0 };
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void reverse1(char s[])//反转字符串
{
int len = strlen(s);
for (int i = 0; i < len; i++)
{
reverse(s[i], s[len - i - 1]);
}
}
int main(int argc, char** argv) {
cin >> A;
cin >> B;
int lenA = strlen(A);
int lenB = strlen(B);
int len = lenA > lenB ? lenA : lenB;
for (int i = 0; i < len; i++)
{
int numA = i < lenA ? A[i] - '0' : 0;
int numB = i < lenB ? B[i] - '0' : 0;
if (i % 2 == 0)
{
int temp = (numB + numA) % 13;
if (temp == 10)
ans[i] = 'J';
else if (temp == 11)
ans[i] = 'Q';
else if (temp == 12)
ans[i] = 'K';
else
ans[i] = temp + '0';
}
else//当前位数为奇数;
{
int temp = (numB - numA) >= 0 ? (numB - numA) : (numB - numA + 10);
ans[i] = temp + '0';
}
}
reverse1(ans);
puts(ans);
return 0;
}