summaryrefslogtreecommitdiffstats
path: root/inf/zotksd/1.c
blob: 7a2de18cffb16bee3a013f04b14ffa4b7441c042 (plain) (blame)
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
// naloge ne razumem najbolje
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define S 25000
int main (void) {
	int crke[25];
	char buf[S];
	fgets(buf, S, stdin);
	int n = strtol(buf, NULL, 10);
	for (int i = 0; i < n; i++) {
		int crkecopy[25];
		memcpy(crkecopy, crke, sizeof(crke));
		fgets(buf, S, stdin);
		char dodaten = -1;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
		if (strlen(buf) != i+1 && 0) {
#ifndef EVAL
			fprintf(stderr, "napačna dolžina niza %s na indeksu %d\n", buf, i);
#endif
			printf("%d\n", i);
			return 0;
		}
#pragma GCC diagnostic pop
#ifndef EVAL
		fprintf(stderr, "pri i==%d obdelujem niz %s", i, buf);
#endif
		for (int j = 0; j <= i; j++) {
			int crka = buf[j]-'A';
			if (--crkecopy[crka] < 0) {
				if (dodaten != -1) {
					printf("%d\n", i);
#ifndef EVAL
					fprintf(stderr, "konec, ker je preveč novih, dodaten je %c\n", dodaten+'A');
#endif
					return 0;
				}
				dodaten = crka;
#ifndef EVAL
				fprintf(stderr, "i==%d, dodaten je sedaj %c\n", i, dodaten+'A');
#endif
				crke[crka]++;
			}
		}
		for (int j = 0; j < 25; j++)
			if (crkecopy[j] != 0 && crkecopy[j] != -1) {
				printf("%d\n", i);
#ifndef EVAL
				fprintf(stderr, "konec, ker ni pobrisal vseh\n");
#endif
				return 0;
			}
	}
	printf("%d\n", n);
	return 0;
}