Luo Gu div2 [XR-4] singing contest

 

It is limited, at the problem is not the solution, a lot of understanding

 

Thank you view this konjac

 

 

Topic : Portal

 

 

There are topics where there is no clear:

1: That little X of each digit of the number of points in praise and small == Y of each digit of the number of points like this and ( is this cancer cause I only have 11 minutes )

2: appears to -1, from left to right occurs first the Z , if after as long as one of X or the Y , then it can not be derived, the output of -1

Analog to

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\n");
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 }

 

Guess you like

Origin www.cnblogs.com/nlyzl/p/11714909.html