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

ShineEternal

2019-10-21 18:13:45

Solution

### [$my\ blog$](https://blog.csdn.net/kkkksc03) ## solution: 此题我个人认为像是一道类似愚人节的题目。。。 其实特别简单,但是我挂在了一句话上: > 果我们再用 Z 表示小 X 与小 Y 的**点赞数**暂时一样 这里不小心惯性思维想成了只有那一位相等,其实是都相等。。。 于是此时问题就简单了,无解就是在Z后面还有X或Y,先判断完无解再正常判断X和Y即可(可以用0,1赋值) ## code: ```cpp #include<cstdio> #include<cstring> using namespace std; char s[1000005]; int a[1000005],b[1000005]; int main() { scanf("%s",s); int n=strlen(s); int pd=0; for(register int i=0;i<n;i++) { if(s[i]=='Z') { pd=1; } if(pd&&s[i]!='Z') { printf("-1\n"); return 0; } } for(register int i=n-1;i>=0;i--) { if(s[i]=='X') { a[i]=1; } if(s[i]=='Y') { b[i]=1; } } for(register int i=0;i<n;i++) { printf("%d",a[i]); } printf("\n"); for(register int i=0;i<n;i++) { printf("%d",b[i]); } return 0; } ```