-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_win.c
68 lines (48 loc) · 1.52 KB
/
input_win.c
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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// #include <sys/time.h>
// #include <sys/resource.h>
#include <time.h>
#include "string_info.h"
// TODO: change here to include your files!!
#include "middlesub/grpwk.h"
int main_prg(int, char **);
int main(int argc, char **argv)
{
// struct rusage u;
// getrusage(RUSAGE_SELF, &u);
// struct timeval start = u.ru_utime;
clock_t c_start = clock(), c_end;
main_prg(argc, argv);
// struct timeval end = u.ru_utime;
c_end = clock();
printf("%f\n", (double)(c_end - c_start) / CLOCKS_PER_SEC);
// fprintf(stderr, "%lf\n", (double)(end.tv_sec - start.tv_sec) + (double)(end.tv_usec - start.tv_usec) * 1e-6);
return 0;
}
int sort_f(const void *a, const void *b) {
return ((string_s *)b)->len - ((string_s *)a)->len;
}
int main_prg(int argc, char **argv)
{
assert(argc == 3);
FILE *fp_in = fopen(argv[1], "r");
assert(fp_in != NULL);
FILE *fp_out = fopen(argv[2], "w");
assert(fp_out != NULL);
char t[T_LENGTH];
string_s s[50000];
//s = malloc(sizeof(string_s) * 50000);
// input t
fscanf(fp_in, "%s", t);
// for (int i=0; i<T_LENGTH; i++) if (t[i] == 'x') t[i] = 'a';
// input s[]
int counter = 0;
for (; fscanf(fp_in, "%s", s[counter].str) != EOF; ++counter) s[counter].len = strlen(s[counter].str);
qsort(s, counter, sizeof(string_s), sort_f);
for (int i=0; i<counter; i++) s[i].id = i;
fprintf(fp_out, "%s\n", grpwk(t, s, counter));
return 0;
}