1546B - AquaMoon and Stolen String

链接:

https://codeforces.com/problemset/problem/1546/B

题意:

n个m长度字符串,n固定为奇数

将一条拿走,其他的字符串可以交换下标相同位置上的字符

再给你其中n-1个字符串的原字符串,求拿走的字符串是什么;

输入

3
3 5
aaaaa
bbbbb
ccccc
aaaaa
bbbbb
3 4
aaaa
bbbb
cccc
aabb
bbaa
5 6
abcdef
uuuuuu
kekeke
ekekek
xyzklm
xbcklf
eueueu
ayzdem
ukukuk

输出量

ccccc
cccc
kekeke

解:

计算给定n个字符串每个位置上的字符总和,再减去给的n-1个字符串每个位置上的字符总和,多出来的一个就是被拿走字符串该位置的字符

实际代码:

#include<iostream>
#include<bits/stdc++.h>
#define csh(a) memset(a,0,sizeof(a))
using namespace std;
const int N=1E5+5;
int dw[N][27];
int main()
{
	int t;
	cin>>t;
	for(int f=1;f<=t;f++)
	{
		csh(dw);
		int n,m;
		cin>>n>>m;
		for(int i=1;i<=n;i++)
		{
			string s;
			cin>>s;
			int lg=s.length();
			for(int j=0;j<lg;j++)
			{
				int mao=s[j]-'a';
				dw[j][mao]++;
			}
		}
		for(int i=1;i<=n-1;i++)
		{
			string s;
			cin>>s;
			int lg=s.length();
			for(int j=0;j<lg;j++)
			{
				int mao=s[j]-'a';
				dw[j][mao]--;
			}
		}
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<26;j++)
			{
				if(dw[i][j]==1)
				{
					cout<<(char)(j+'a');
					break;
				}
			}
		}
		cout<<endl;
	}
}

限制:

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值