summaryrefslogtreecommitdiffstats
path: root/inf/zotks/2/Sosedska_stevila.c
blob: eb067028fdb138cdee216b1cd8afa343f9834c01 (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
58
59
60
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int popravi(char * b) {
	int i = 0;
	int spremenil = 0;
	for (i = strlen(b)-1; i > 0; i--) {
		if (b[i] > '9') {
			b[i] = '0';
			b[i-1]++;
			spremenil++;
		}
	}
	if (b[0] > '9') {
		/* fprintf(stderr, "debug\n");; */
		memcpy(b+1, b, 24);
		b[1] = '0';
		b[0] = '1';
		spremenil++;
	}
	return spremenil;
}
int jeok (char * b) {
	int se_enkrat = 0;
	for (int i = 0; b[i+1] != '\0'; i++) {
		if (b[i] == b[i+1]) {
			b[i+2]++;
			if (popravi(b))
				se_enkrat++;
		}
	}
	if (se_enkrat)
		return jeok(b);
	return 0;
}
int main (int argc, char ** argv) {
	char b[25]; /* vemo, kako veliko je št */
	char c = fgetc(stdin);
	unsigned long long int i = 0;
	while (!feof(stdin)) {
		b[i++] = c;
		c = fgetc(stdin);
	}
	b[i--] = '\0';
	fprintf(stderr, "poganjam %s\n", b);
	fflush(stderr);
	b[i]++;
	popravi(b);
	jeok(b);
	fprintf(stdout, "%s\n", b);
	return 0;
}
/*
	int main (int argc, char ** argv) {
		char c[1234];
		strcpy(c, argv[1]);
		popravi(c);
		fprintf(stdout, "%s\n", c);
	}
*/