一、题目描述
二、AC 代码
为了锻炼大家阅读代码的能力,本题解将不撰写算法分析说明与代码编写指导。
#include<cstdio>
#pragma warning(disable: 4996)
typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint;
typedef long long ll; typedef unsigned long long ull;
const uint nmax = 5e4 + 1;
char c[nmax], * p, * q, * r, * R, a[nmax], b[nmax]; uint t, n;
int main() {
scanf("%u", &t);
for (uint h = 0; h < t; ++h) {
scanf("%u", &n); getchar();
gets_s(c, nmax); p = a, q = b; R = c + n;
for (r = c; r != R; ++p, ++q, ++r) {
if (*r == '0') { *p = * q = '0'; }
else if (*r == '2') { *p = *q = '1'; }
else { *p = '1'; *q = '0'; ++p; ++q; ++r; break; }
}
for (; r != R; ++p, ++q, ++r) { *p = '0'; *q = *r; }
*p = *q = 0;
puts(a); puts(b);
}
return 0;
}
#include<cstdio>
#pragma warning(disable: 4996)
typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned int uint;
typedef long long ll; typedef unsigned long long ull;
const uint nmax = 5e4 + 1;
char c[nmax], a[nmax], b[nmax]; uint t, n;
int main() {
scanf("%u", &t);
for (uint h = 0; h < t; ++h) {
scanf("%u", &n); getchar();
gets_s(c, nmax); uint i = 0;
for (i = 0; i < n; ++i) {
if (c[i] == '0') { a[i] = b[i] = '0'; }
else if (c[i] == '2') { a[i] = b[i] = '1'; }
else { a[i] = '1'; b[i] = '0'; ++i; break; }
}
for (; i < n; ++i) { a[i] = '0'; b[i] = c[i]; }
a[n] = b[n] = 0;
puts(a); puts(b);
}
return 0;
}