Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <string.h>
  6.  
  7. int main(void) {
  8.     freopen("output.txt", "w", stdout);
  9.     srand(time(NULL));
  10.     int n, m, a, minV = INT_MAX;
  11.     int i, j;
  12.     char ans[100] = "";
  13.     char buf[10];
  14.     n = rand() % 30 + 1;
  15.     int* u = (int*)malloc(n*sizeof(int));
  16.     for(i = 0; i < n; i++)
  17.         u[i] = 0;
  18.     for(i = 0; i < n; i++) {
  19.         m = rand() % 20 + 1;
  20.         for(j = 0; j < m; j++) {
  21.             a = rand()-INT_MAX/2;
  22.             printf("%d ", a);
  23.             if(a < minV) {
  24.                 u[i] = 1;
  25.                 minV = a;
  26.                 sprintf(buf, "%d", i+1);
  27.                 strcpy(ans, buf);
  28.                 strcat(ans, " ");
  29.             } else if(a == minV) {
  30.                 if(!u[i]) {
  31.                     u[i] = 1;
  32.                     sprintf(buf, "%d", i+1);
  33.                     strcat(ans, buf);
  34.                     strcat(ans, " ");
  35.                 }
  36.             }
  37.         }
  38.         printf("\n");
  39.     }
  40.     printf("%s", ans);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement