Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 10000
- int main(void) {
- FILE *in = fopen("bids.txt", "r");
- if (!in) {
- exit(1);
- }
- char *names[N];
- int bids[N] = {0};
- int used = 0;
- for (char buf[BUFSIZ]; fgets(buf, BUFSIZ, in);) {
- char name[BUFSIZ];
- int bid;
- if (sscanf(buf, "%s%d", name, &bid) == 2) {
- int i = 0;
- for (; i < used; ++i) {
- if (!strcmp(names[i], name)) {
- break;
- }
- }
- if (i == used) {
- names[used++] = strdup(name);
- }
- if (bids[i] < bid) {
- bids[i] = bid;
- }
- }
- }
- fclose(in);
- FILE *out = fopen("output.txt", "w");
- if (!out) {
- exit(1);
- }
- for (int i = 0; i < used; ++i) {
- fprintf(out, "%s %d\n", names[i], bids[i]);
- free(names[i]);
- }
- fclose(out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement