欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

2020 CCPC Wannafly Winter Camp Day1 Div1&2(重现赛)B题解

程序员文章站 2022-07-12 15:06:42
...

链接:https://ac.nowcoder.com/acm/contest/3979/B
来源:牛客网

B,签到题。按m->1倒序来依次还原字符串。

#include<bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<stdio.h>
#include<string>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define ll long long

using namespace std;
const ll N = 10000;
int n, m, chul[N][3];
string p[N];
int getnum(char c)
{
	if (c >= 'A' && c <= 'Z')
		return c - 'A' + 26;
	return c - 'a';
}
char getst(int c)
{
	if (c <= 25)
		return char(c + 'a');
	else
		return char(c - 26 + 'A');
}
int main()
{
	//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("182.txt", "r", stdin);
#endif // ONLINE_JUDGE
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", &chul[i][1], &chul[i][2]);
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> p[i];
	}
	for (int i = m; i; i--)
	{
		int bcl = chul[i][2];//被处理的字符串编号
		int cl = chul[i][1];//处理字符串;
		string a = p[cl], b = p[bcl], c = "";//a是处理的,b是被处理的,c用来还原、 
		while (a.size() < b.size())//拓展a 
			a = a + a;
		for (int i = 0; i < b.size(); i++)//开始还原,c[i]+a[i]%52=b[i]->>c[i]=b[i]+52-a[i]%52; 
		{
			char t = (getst((getnum(b[i]) + 52 - getnum(a[i])) % 52));
			c += t;
		}
		p[bcl] = c;
	}
	
	for (int i = 1; i <= n; i++)
		cout << p[i] << endl;
	return 0;
}