CodeForces - 1144E 【模拟,进制】

题意:给出长度为n的两个串,求他们中位数串。比如aa cc,中位数串就是bb,题目保证这俩中间的串个数是奇数。

思路:就是26进制的加法模拟,再/2。QAQ习惯性大数写成结构体,局部爆栈了,愣是看不出来,加static才行,不过这里直接用数组就行了。

代码:

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxv = 2e5 + 5;

int n;
string s1, s2;
int a[maxv], b[maxv];

int main()
{
	cin >> n;
	cin >> s1;
	cin >> s2;
	int cnt = 0,up=0;
	for (int i = n - 1; i >= 0; i--)
	{
		int now = s1[i] - 'a' + s2[i] - 'a' + up;
		a[cnt++] = now % 26;
		up = now / 26;
	}
	if (up)
	{
		a[cnt++] = up;
	}
	int lst = 0;
	int ct = 0;
	for (int i = cnt - 1; i >= 0; i--)
	{
		int now = lst * 26 + a[i];
		if (now < 2)
		{
			b[i] = 0;
			lst = now;
		}
		else
		{
			b[i] = now / 2;
			lst = now % 2;
		}
	}
	for (int i = cnt-1; i >=0; i--)
	{
		if (i == cnt - 1 && cnt > n&&b[i] == 0)
			continue;
		printf("%c", b[i] + 'a');
	}
	cout << endl;
	return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值