Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #ifndef DEBUG
- #define DEBUG(...) printf(__VA_ARGS__)
- #endif
- #define VEL 10000
- void ispis(int n, char *polje[]) {
- int i;
- for (i = 0; i < n-1; i++) {
- if (atoi(*(polje+i)) >= atoi(*(polje+i+1))) {
- printf("NO");
- return;
- }
- }
- printf("YES\n");
- for (i = 0; i < n; i++) {
- printf("%s\n", *(polje+i));
- }
- }
- int nadi_broj(int n, int p, char *polje[], char *manji, char *trenutni, char *tmp) {
- int l_novi, l_tmp = strlen(tmp);
- unsigned long i;
- int manji_int, k;
- char novi[9], *novi2;
- manji_int = atoi(manji);
- novi2 = (char*) malloc(strlen(manji)*sizeof(char));
- sprintf(novi2, "%d", manji_int+1);
- for (i = manji_int+1; i <= atoi(trenutni)*10; i++) {
- //printf("i je %li\n", i);
- sprintf(novi, "%lu", i);
- for (k = 0; k < l_tmp; k++) {
- while ((novi[k] != tmp[k]) && tmp[k] != '?') {
- i++;
- sprintf(novi, "%lu", i);
- }
- l_novi = strlen(novi);
- }
- if (l_novi < l_tmp) {
- continue;
- }
- else if(isdigit(*novi) && l_novi <= l_tmp) {
- sprintf(*(polje+p), "%s", novi);
- free(novi2);
- return 0;
- }
- else {
- free(novi2);
- return -1;
- }
- }
- return 0;
- }
- void check_for_question_mark(int n, char *polje[]) {
- int i, k, length_manji, length_trenutni, val, ulaz = 1, izlaz = 1;
- char *tmp_manji, *tmp_trenutni, *tmp;
- for (i = 0; i < n; i++) {
- izlaz = 1;
- length_trenutni = strlen(*(polje+i));
- tmp_trenutni = (char*) malloc(length_trenutni*sizeof(char));
- tmp_trenutni = *(polje+i);
- tmp = (char*) malloc(length_trenutni*sizeof(char));
- strcpy(tmp, *(polje+i));
- if (i == 0) {
- length_manji = strlen(*(polje+i));
- tmp_manji = (char*) malloc(length_manji*sizeof(char));
- tmp_manji = *(polje+i);
- } else {
- length_manji = strlen(*(polje+i-1));
- tmp_manji = (char*) malloc(length_manji*sizeof(char));
- tmp_manji = *(polje+i-1);
- }
- for (k = length_trenutni; k >= 0; k--) {
- if (tmp_trenutni[k] == '?') {
- if (length_trenutni == 1 && i == 0) {
- sprintf(*(polje+i), "%d", 1);
- } else if (i == 0 && length_trenutni != 1) {
- if (k == 0) {
- tmp_trenutni[k] = '1';
- } else {
- tmp_trenutni[k] = '0';
- }
- } else if (i > 0){
- ulaz = strlen(tmp_trenutni);
- while (ulaz != 0) {
- izlaz *= 10;
- ulaz--;
- }
- izlaz/=10;
- //printf("izlaz je %d\n", izlaz);
- sprintf(tmp_trenutni, "%d", izlaz);
- //printf("usao sam s %s\n", tmp_trenutni);
- //printf("usao sam s brojem %s i prethodnim %s\n", tmp_trenutni, tmp_manji);
- val = nadi_broj(n, i, polje, tmp_manji, tmp_trenutni, tmp);
- }
- }
- }
- }
- if (val != -1) {
- ispis(n, polje);
- } else {
- printf("NO");
- }
- }
- void check_if_possible(int n, char *polje[]) {
- int i, length1, length2;
- for (i = 0; i < n-1; i++) {
- length1 = strlen(*polje+i);
- length2 = strlen(*(polje+i+1));
- if (length1 > length2) {
- printf("NO");
- return;
- }
- }
- check_for_question_mark(n, polje);
- }
- int main(int argc, char **argv){
- int i, n;
- scanf("%d", &n);
- char *polje[n];
- for (i = 0; i < n; ++i) {
- polje[i] = (char*)malloc(sizeof(int));
- scanf("%s", polje[i]);
- }
- check_if_possible(n, polje);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement