1. 程式人生 > 實用技巧 >HihoCoder 1871 B. Heshen's Account Book

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; }