Advertisement
Dr4noel

Ceva Ce nu Vrei sa Vezi

May 16th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. void Afisare(int a[],int n) {
  7.     for (int i = 0; i < n; i++) {
  8.         printf("%d ", a[i]);
  9.     }
  10.     printf("\n");
  11. }
  12.  
  13. void Sortare(int a[],int b[],int n) {
  14.     int glass;
  15.  
  16.     for (int i = 0; i < n - 1; i++) {
  17.         for (int j = i + 1; j < n; j++) {
  18.             if (a[i] > a[j]) {
  19.                 glass = a[i];
  20.                 a[i] = a[j];
  21.                 a[j] = glass;
  22.  
  23.                 glass = b[i];
  24.                 b[i] = b[j];
  25.                 b[j] = glass;
  26.             }
  27.         }
  28.     }
  29. }
  30.  
  31. void MakeThemUnic(int vector1[], int vectorDeControl[], int n) {
  32.     int k;
  33.     for (int i = 0; i < n; i++) {
  34.         vectorDeControl[i] = vector1[i];
  35.     }
  36.  
  37.     for (int i = 0; i < n; i++) {
  38.         k = 0;
  39.         for (int j = 0; j < n; j++) {
  40.             if (vector1[i] == vectorDeControl[j]) {
  41.                 k++;
  42.                 while (vector1[i] == vectorDeControl[j] && k >= 2) {
  43.                     vector1[j] = rand() % 11 + 1;
  44.                     vectorDeControl[j] = vector1[j];
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. void endHour(int vector1[], int vector2[], int n) {
  52.     time_t t;
  53.     srand(unsigned(time(&t)));
  54.  
  55.     for (int i = 0; i < n; i++) {
  56.         vector2[i] = vector1[i] + rand() % 2 + 1;
  57.     }
  58. }
  59. void main() {
  60.     time_t t;
  61.     srand(unsigned(time(&t)));
  62.  
  63.     const int n = 7;
  64.     int a[n];
  65.     int b[n];
  66.     int c[n];
  67.  
  68.     for (int i = 0; i < n; i++) {
  69.         a[i] = rand() % 11 + 1;
  70.         b[i] = rand() % 11 + 2;
  71.     }
  72.  
  73.     MakeThemUnic(a, c, n);
  74.     endHour(a, b, n);
  75.  
  76.     Afisare(a, n);
  77.     Afisare(b, n);
  78.  
  79.     Sortare(a, b, n);
  80.     printf("\nSortat : \n");
  81.     Afisare(a, n);
  82.     Afisare(b, n);
  83.  
  84.     _getch();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement