Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <limits.h>
- #include <string.h>
- enum
- {
- MAX_DIGITS = 10
- };
- void
- outpt(int* ans)
- {
- for (int i = 0; i < MAX_DIGITS; ++i) {
- printf("%d %d\n", i, ans[i]);
- }
- }
- int
- main(void)
- {
- int cnt[MAX_DIGITS];
- memset(cnt, 0, MAX_DIGITS * sizeof(int));
- char raw[PATH_MAX + 1];
- if (fgets(raw, PATH_MAX, stdin) == NULL) {
- outpt(cnt);
- return 0;
- }
- int it = PATH_MAX;
- while (it >= 0 && raw[it] != '\n') {
- --it;
- }
- for (int i = 0; i < 3; ++i, --it) {
- if (it >= 0 && (raw[it] == '\r' || raw[it] == '\n')) {
- raw[it] = 0;
- }
- }
- FILE *inpt = fopen(raw, "r");
- if (inpt == NULL) {
- outpt(cnt);
- return 0;
- }
- int curr;
- while((curr = getc_unlocked(inpt)) != EOF) {
- if ('0' <= curr && curr <= '9') {
- ++cnt[curr - '0'];
- }
- }
- outpt(cnt);
- pclose(inpt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment