洛谷div2【XR-4】歌唱比赛

本人水平有限,题解不到为处,请多多谅解

本蒟蒻谢谢大家观看

题目传送门

题目有地方没有说清楚:

1:即小X的各个位数的点赞数之和==小Y的各个位数的点赞数之和(就是这个毒瘤导致我只有11分

2:出现-1的情况,从左往右出现第一个Z时,若之后只要有一个为X或Y,那么就无法得出,输出-1

模拟即可

code:

 1 #include<bits/stdc++.h>
 2 #pragma GCC optimize(3)
 3 const int N=1e6+100;
 4 using namespace std;
 5 string ch;
 6 int len;
 7 int k[N],h[N],tot,cnt,wz[N];
 8 inline int read(){
 9     int x=0,f=1;char ch=getchar();
10     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
11     while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
12     return x*f;
13 }
14 inline void write(int x){
15      char F[200];
16      int tmp=x>0?x:-x ;
17      if(x<0)putchar('-') ;
18      int cnt=0 ;
19         while(tmp>0)
20         {
21             F[cnt++]=tmp%10+'0';
22             tmp/=10;
23         }
24         while(cnt>0)putchar(F[--cnt]) ;
25 }
26 void solve1(){
27     if(ch[0]=='X'){
28         cout<<3<<endl;
29         cout<<2<<endl;
30         return ;
31     }
32     if(ch[0]=='Y'){
33         cout<<2<<endl;
34         cout<<3<<endl;
35         return ;
36     }
37     if(ch[0]=='Z'){
38         cout<<1<<endl;
39         cout<<1<<endl;
40         return ;
41     } 
42     return ;
43 }
44 void solve2(){
45     for(int i=0;i<len;i++){
46         if(ch[i]=='X'){
47             k[++tot]=9;
48             h[++cnt]=0;
49         }
50         if(ch[i]=='Y'){
51             k[++tot]=0;
52             h[++cnt]=9;
53         }
54         if(ch[i]=='Z'){
55             k[++tot]=1;
56             h[++cnt]=1;
57             wz[i]=1;
58         }
59     }
60     for(int i=0;i<len-1;i++){
61         if(wz[i]!=0){
62         if(wz[i]!=wz[i+1]){
63             printf("-1
");
64             return ;
65         }
66         //cout<<"wz= "<<wz[i]<<endl;
67     }
68     }
69     for(int i=1;i<=tot;i++){
70         printf("%d",k[i]);
71     }
72     cout<<endl;
73     for(int i=1;i<=cnt;i++){
74         printf("%d",h[i]);
75     }
76     return ;
77 }
78 int main()
79 {
80     cin>>ch;
81     len=ch.size();
82     //cout<<"len= "<<ch[1]<<endl;
83     if(len==1)solve1();
84     else solve2();
85     return 0;
86 }
原文地址:https://www.cnblogs.com/nlyzl/p/11714909.html