1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include <bits/stdc++.h> using namespace std; typedef long long ll;
#define N 2000007
int b[N], tot;
int Data[N * 10];
void add(int o, int l) { if (o >= l) { int p = tot - o + 1; for (int i = 1; i <= l; ++i) Data[++tot] = Data[p++]; } else { int pp = tot - o + 1; int p = pp; for (int i = 1; i <= l; ++i) { Data[++tot] = Data[p++]; if (i % o == 0) p = pp; } } }
void pt(int x) { if (x < 10) putchar(x + '0'); else putchar(x + 'a' - 10); }
void print(int x) { pt(x >> 4); pt(x & 15); }
int main() { int n; scanf("%d", &n); bool f = 0; for (int i = 1, x; i <= n; ++i) { char c = getchar(); while (!isdigit(c) && !isalpha(c)) c = getchar(); x = isdigit(c) ? (c - '0') : (c - 'a' + 10); c = getchar(); x = (x << 4) + (isdigit(c) ? (c - '0') : (c - 'a' + 10)); if (f) b[++tot] = x; if ((x & (1 << 7)) == 0) f = true; } n = tot; tot = 0; for (int i = 1; i <= n; ++i) { if ((b[i] & 3) == 0) { int l = b[i] >> 2; if (l >= 60) { int tmpk = l - 59; l = 0; for (int j = i + tmpk; j > i; --j) l = (l << 8) + b[j]; i += tmpk; } ++l; for (; l; --l) Data[++tot] = b[++i]; } else if ((b[i] & 3) == 1) { int l = ((b[i] >> 2) & 7) + 4; int o = ((b[i] >> 5) << 8); o += b[++i]; add(o, l); } else { int l = (b[i] >> 2) + 1; int o = (b[i + 2] << 8) + b[i + 1]; i += 2; add(o, l); } } for (int i = 1; i <= tot; ++i) { print(Data[i]); if (i % 8 == 0) puts(""); } return 0; }
|