C. Manipulating History

Problem - 1688C - Codeforces

思路:因为它给定了最终的串,能够想到能够通过逆操作将整个序列变回去,那我们需要有一个形式str,a,b即在str中将a替换为b,很容易能够看出来,a中的字符串出现了两次,在str中一次,在a中一次,而str中余下的仅出现了一次,替换完之后的b也仅出现了一次,这时我们发现了一个性质,就是在替换完之后保留的这个串str'中的字符在序列中仅出现了一次,因为最后会只剩下一个字符,所以就代表这最后一个字符仅出现了一次,所以我们只需要统计所有的字符串中所有的字符的个数,出现为奇数的那个字符就是最初的原字符

cpp 复制代码
// Problem: C. Manipulating History
// Contest: Codeforces - Codeforces Round 796 (Div. 2)
// URL: https://codeforces.com/problemset/problem/1688/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms

#include<bits/stdc++.h>
#include<sstream>
#include<cassert>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}

int T,hackT;
int n,m,k;
char str[N];
int cnt[30];

void solve() {
	n=read();
	
	memset(cnt,0,sizeof cnt);
	for(int i=1;i<=2*n+1;i++) {
		scanf("%s",str+1);
		int len=strlen(str+1);
		for(int j=1;j<=len;j++) cnt[str[j]-'a']++;
	}
	
	for(int j=0;j<26;j++) {
		if(cnt[j]%2==1) printf("%c\n",j+'a');
	}
}   

int main() {
    // init();
    // stin();
	// ios::sync_with_stdio(false); 

    scanf("%d",&T);
    // T=1; 
    while(T--) hackT++,solve();
    
    return 0;       
}          
相关推荐
闻缺陷则喜何志丹16 分钟前
【贪心 字典序 回文 最长公共前缀】LeetCode3734. 大于目标字符串的最小字典序回文排列|分数未知
c++·算法·力扣·贪心·字典序·回文·最长公共前缀
weixin_5142218534 分钟前
FDTD代码学习-1
学习·算法·lumerical·fdtd
AI柠檬1 小时前
机器学习:数据集的划分
人工智能·算法·机器学习
让我们一起加油好吗2 小时前
【数论】裴蜀定理与扩展欧几里得算法 (exgcd)
算法·数论·裴蜀定理·扩展欧几里得算法·逆元
Geo_V2 小时前
提示词工程
人工智能·python·算法·ai
侯小啾2 小时前
【22】C语言 - 二维数组详解
c语言·数据结构·算法
TL滕2 小时前
从0开始学算法——第一天(如何高效学习算法)
数据结构·笔记·学习·算法
傻童:CPU2 小时前
DFS迷宫问题
算法·深度优先
B站_计算机毕业设计之家2 小时前
计算机视觉:python车辆行人检测与跟踪系统 YOLO模型 SORT算法 PyQt5界面 目标检测+目标跟踪 深度学习 计算机✅
人工智能·python·深度学习·算法·yolo·目标检测·机器学习
一个不知名程序员www3 小时前
算法学习入门---前缀和(C++)
c++·算法