HihoCoder 1871 B. Heshen's Account Book
离谱的语文题
5点的时候我说,这不是傻逼题吗,我来打,最后看了题解之后八点多才做出来,太离谱了
1abc111abc1可以提炼出11111这个数字(这谁看的出来呀)
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e6 + 10; char s[N]; int ans[N], h[N]; #define isdight(x) (x >= '0' && x <= '9') int main() { int p = 0, last = 0, cnt = 1, last_p = 0; while (scanf("%[^\n]", &s[p]) != EOF) { getchar(); p = strlen(s); s[p++] = ' '; for (int i = last; i < p; i++) h[i] = cnt; cnt++; char c; if ((c = getchar()) == EOF) break; if (isdigit(c) && isdigit(s[p - 2])) p--; last = p; s[p++] = c; last_p = p; h[p - 1] = cnt; } if (last_p == p) cnt++, s[p++] = ' '; int len = strlen(s); int pos = 0; for (int i = 0; i <= len; i++) { if (s[i] == ' ' || s[i] == '\r' || s[i] == '\n') { if (!isdigit(s[pos]) || !isdigit(s[i - 1])); else if (s[pos] == '0') { if (i - pos == 1) { ans[h[pos]]++; printf("0 "); } } else { for (int j = pos; j < i; j++) if (isdigit(s[j])) printf("%c", s[j]); if (pos < i) printf(" "), ans[h[pos]]++; } pos = i + 1; } else { pos = min(pos, i); } } puts(""); for (int i = 1; i < cnt; i++) printf("%d\n", ans[i]); return 0; }