总结
reverse是在algorithm中,并且,使用时,必须要放的是地址,如reverse(s,s+a);
#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-1-i);//reverse中放的,一定是地址,不然会报错
}
}
int main(int argc, char** argv) {
cin >> A;
cin >> B;
reverse1(A);
reverse1(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;
}