Advertisement
Guest User

Untitled

a guest
May 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5.  
  6. #ifndef DEBUG
  7. #define DEBUG(...) printf(__VA_ARGS__)
  8. #endif
  9.  
  10. #define VEL 10000
  11.  
  12. void ispis(int n, char *polje[]) {
  13. int i;
  14. for (i = 0; i < n-1; i++) {
  15. if (atoi(*(polje+i)) >= atoi(*(polje+i+1))) {
  16. printf("NO");
  17. return;
  18. }
  19. }
  20. printf("YES\n");
  21. for (i = 0; i < n; i++) {
  22. printf("%s\n", *(polje+i));
  23. }
  24. }
  25.  
  26. int nadi_broj(int n, int p, char *polje[], char *manji, char *trenutni, char *tmp) {
  27. int l_novi, l_tmp = strlen(tmp);
  28. unsigned long i;
  29. int manji_int, k;
  30. char novi[9], *novi2;
  31. manji_int = atoi(manji);
  32. novi2 = (char*) malloc(strlen(manji)*sizeof(char));
  33. sprintf(novi2, "%d", manji_int+1);
  34. for (i = manji_int+1; i <= atoi(trenutni)*10; i++) {
  35. //printf("i je %li\n", i);
  36. sprintf(novi, "%lu", i);
  37. for (k = 0; k < l_tmp; k++) {
  38. while ((novi[k] != tmp[k]) && tmp[k] != '?') {
  39. i++;
  40. sprintf(novi, "%lu", i);
  41. }
  42. l_novi = strlen(novi);
  43. }
  44. if (l_novi < l_tmp) {
  45. continue;
  46. }
  47. else if(isdigit(*novi) && l_novi <= l_tmp) {
  48. sprintf(*(polje+p), "%s", novi);
  49. free(novi2);
  50. return 0;
  51. }
  52. else {
  53. free(novi2);
  54. return -1;
  55. }
  56. }
  57. return 0;
  58. }
  59.  
  60. void check_for_question_mark(int n, char *polje[]) {
  61. int i, k, length_manji, length_trenutni, val, ulaz = 1, izlaz = 1;
  62. char *tmp_manji, *tmp_trenutni, *tmp;
  63. for (i = 0; i < n; i++) {
  64. izlaz = 1;
  65. length_trenutni = strlen(*(polje+i));
  66. tmp_trenutni = (char*) malloc(length_trenutni*sizeof(char));
  67. tmp_trenutni = *(polje+i);
  68. tmp = (char*) malloc(length_trenutni*sizeof(char));
  69. strcpy(tmp, *(polje+i));
  70. if (i == 0) {
  71. length_manji = strlen(*(polje+i));
  72. tmp_manji = (char*) malloc(length_manji*sizeof(char));
  73. tmp_manji = *(polje+i);
  74. } else {
  75. length_manji = strlen(*(polje+i-1));
  76. tmp_manji = (char*) malloc(length_manji*sizeof(char));
  77. tmp_manji = *(polje+i-1);
  78. }
  79. for (k = length_trenutni; k >= 0; k--) {
  80. if (tmp_trenutni[k] == '?') {
  81. if (length_trenutni == 1 && i == 0) {
  82. sprintf(*(polje+i), "%d", 1);
  83. } else if (i == 0 && length_trenutni != 1) {
  84. if (k == 0) {
  85. tmp_trenutni[k] = '1';
  86. } else {
  87. tmp_trenutni[k] = '0';
  88. }
  89. } else if (i > 0){
  90. ulaz = strlen(tmp_trenutni);
  91. while (ulaz != 0) {
  92. izlaz *= 10;
  93. ulaz--;
  94. }
  95. izlaz/=10;
  96. //printf("izlaz je %d\n", izlaz);
  97. sprintf(tmp_trenutni, "%d", izlaz);
  98. //printf("usao sam s %s\n", tmp_trenutni);
  99. //printf("usao sam s brojem %s i prethodnim %s\n", tmp_trenutni, tmp_manji);
  100. val = nadi_broj(n, i, polje, tmp_manji, tmp_trenutni, tmp);
  101. }
  102. }
  103. }
  104. }
  105. if (val != -1) {
  106. ispis(n, polje);
  107. } else {
  108. printf("NO");
  109. }
  110. }
  111.  
  112. void check_if_possible(int n, char *polje[]) {
  113. int i, length1, length2;
  114. for (i = 0; i < n-1; i++) {
  115. length1 = strlen(*polje+i);
  116. length2 = strlen(*(polje+i+1));
  117. if (length1 > length2) {
  118. printf("NO");
  119. return;
  120. }
  121. }
  122. check_for_question_mark(n, polje);
  123. }
  124.  
  125.  
  126. int main(int argc, char **argv){
  127. int i, n;
  128. scanf("%d", &n);
  129. char *polje[n];
  130. for (i = 0; i < n; ++i) {
  131. polje[i] = (char*)malloc(sizeof(int));
  132. scanf("%s", polje[i]);
  133. }
  134. check_if_possible(n, polje);
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement