比赛 csp2025模拟练习1 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 麻烦的键盘 最终得分 100
用户昵称 李奇文 运行时间 0.487 s
代码语言 C++ 内存使用 4.83 MiB
提交时间 2025-10-28 11:25:50
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,m,f,id,p,q,cnt,a[N],b[N],c[26];
string sa,sb;
int main(){
	freopen("troublekey.in","r",stdin);
	freopen("troublekey.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>sa>>sb;
	n=sa.length();
	m=sb.length();
	for(int i=1;i<=n;i++){
		a[i]=sa[i-1]-'a';
	}
	for(int i=1;i<=m;i++){
		b[i]=sb[i-1]-'a';
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<26;j++){
			if(i==j){
				continue;
			}
			p=0,f=1,cnt=0,id=1;
			for(int k=0;k<26;k++) c[k]=0;
			for(int k=1;k<=n;k++){
				int ak=a[k];
				if(ak==i){
					q=1;
				}else{
					if(ak==j){
						q=2;
					}else{
						q=0;
					}
				}
				if(q==1){
					if(!c[b[id]]){
						cnt++;
						c[b[id]]++;
					}
					if(cnt>1){
						f=0;
						break;
					}
					++id;
				}else if(q==0){
					if(b[id]!=ak){
						f=0;
						break;
					}
					++id;
				}
				p=q;
			}
			if(id!=m+1||(!f)||(!cnt)) continue;
			cout<<char('a'+i)<<" ";
			for(int k=0;k<26;k++){
				if(c[k]){
					cout<<char('a'+k)<<"\n";
				}
			}
			if(n^m){
				cout<<char(j+'a')<<"\n";
			}else{
				cout<<"-\n";
			}
			return 0;
		}
	}
	return 0;
}