B1048 反转求

总结
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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值