Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #define MAXN 105
- static char a[MAXN];
- int N, D;
- static char num[MAXN];
- static char b[MAXN];
- static int q[MAXN];
- int qc;
- void solve (int point)
- {
- if (point == 5)
- {
- qc = 0;
- int pos = 0;
- while (pos < N)
- {
- if (num[pos]) pos++;
- else
- {
- if (a[pos] > '5')
- {
- int what = (int)(a[pos] - '0');
- if ((what < 6) || (what > D) || (b[what]))
- {
- for (int i = 0; i < qc; i++) b[q[i]] = 0;
- return;
- }
- b[what] = 1;
- q[qc++] = what;
- pos++;
- }
- else
- {
- if ((pos + 1) == N)
- {
- for (int i = 0; i < qc; i++) b[q[i]] = 0;
- return;
- }
- int what = (int)(a[pos] - '0') * 10 + (int)(a[pos+1] - '0');
- if ((what < 6) || (what > D) || (b[what]))
- {
- for (int i = 0; i < qc; i++) b[q[i]] = 0;
- return;
- }
- b[what] = 1;
- q[qc++] = what;
- pos += 2;
- }
- }
- }
- pos = 0;
- char first = 1;
- while (pos < N)
- {
- if (first) first = 0;
- else printf(" ");
- if (num[pos]) printf("%c", a[pos++]);
- else if (a[pos] > '5') printf("%c", a[pos++]);
- else
- {
- printf("%c", a[pos++]);
- printf("%c", a[pos++]);
- }
- }
- printf("\n");
- exit(0);
- }
- else
- {
- int i;
- for (i = 0; i < N; i++)
- {
- if (a[i] == (char)(point) + '1')
- {
- num[i] = 1;
- solve(point+1);
- num[i] = 0;
- }
- }
- }
- }
- int main ()
- {
- scanf("%s",a);
- N = strlen(a);
- if (N < 10)
- {
- printf("%c",a[0]);
- for (int i = 1; i < N; i++) printf(" %c",a[i]);
- printf("\n");
- return 0;
- }
- D = (N - 9) / 2 + 9;
- memset(b,0,sizeof(b));
- solve(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment