C. XOR and OR
There are two strings, a and B. They are composed of 0 and 1 and are not empty;
Change Rule, 1. It can be changed to 2. Select two characters from the string, two types of operations: xor and or; (^ and |); and ask whether the two strings can be changed;
Through the xor and or rules, we can find that 01 can be changed to 11, 11 can be changed to 01 or 10, but it cannot be changed from 11 to 00;
Therefore, if one of a or B contains only 0 and does not contain 1, the conversion cannot be performed; otherwise, the conversion can be performed;
(Of course, if the length of a and B is different, there is NO doubt NO );
The code I started to write was cumbersome. I simplified it step by step, and my thoughts didn't change;
Code 1:
#define maxn 1000100char a[maxn],b[maxn];using namespace std;int main(int argc, char *argv[]){int a_1,b_1;a_1 = b_1 = 0;gets(a);gets(b);if(strlen(a) != strlen(b)){puts("NO");return 0;}for(int i = 0; i < strlen(a); i++){if(a[i]=='1')a_1++;}for(int i = 0; i < strlen(b); i++){if(b[i] == '1')b_1++;}if((a_1==0&&b_1!=0)||(a_1!=0&&b_1==0)){puts("NO");return 0;}elseputs("YES");return 0;}
Code 2:
//Time 46MSMemory 2000KBint main(int argc, char *argv[]){ gets(a); gets(b); if(strlen(a) != strlen(b)) { puts("NO"); return 0; } if((strstr(a,"1")==NULL && strstr(b,"1")!=NULL)||(strstr(a,"1")!=NULL && strstr(b,"1")==NULL)) puts("NO"); else puts("YES"); return 0;}
Final code:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <iomanip>#define maxn 1000100char a[maxn],b[maxn];using namespace std;int main(int argc, char *argv[]){gets(a);gets(b);if(strlen(a) != strlen(b)){puts("NO");return 0;}if((strstr(a,"1")==NULL) ^ (strstr(b,"1")==NULL))puts("NO");elseputs("YES");return 0;}