题解 P5595 【【XR-4】歌唱比赛】

AquaRio

2019-10-20 22:46:17

Solution

**题目传送门:**[\[XR-4\] 歌唱比赛](https://www.luogu.org/problem/P5595) **Description** 有两个数,给出后 $n-i+1$ 位 $(1<=i<=n)$ 组成的数的大小关系。求两个数可能的值。 **Solution** **怎么感觉比第一题还签到?** 其实把大小关系读进来,从后往前扫。 不存在合法的情况,当且仅当出现`Z`前面出现了一个别的字母。我们开一个bool变量,随便维护一下就可以了。 剩下就模拟吧,哪个大了,就给那一位填上较大的数字。 **Code** ```cpp /* Name: [XR-4] 歌唱比赛 Author: Lovely_XianShen Date: 20/10/19 19:18 */ #include<bits/stdc++.h> using namespace std; char qaq[1000005]; int a[1000005],b[1000005]; int main() { bool notdeng=0; scanf("%s",qaq); int len=strlen(qaq); for(int i=len-1; i>=0; i--) { if(qaq[i]=='Z') { if(notdeng==1) { cout<<-1; return 0; } a[i]=3; b[i]=3; } else { notdeng=1; if(qaq[i]=='X') { a[i]=5; b[i]=0; } if(qaq[i]=='Y'){ a[i]=0; b[i]=1; } } } for(int i=0; i<len; i++) printf("%d",a[i]); cout<<endl; for(int i=0; i<len; i++) printf("%d",b[i]); cout<<endl; } ```