Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. /**
  3.  * 2)verif daca 2 vectori sunt anagrama unuia celuilalt
  4.  */
  5. using namespace std;
  6.  
  7. void arraySort(int *a, int n) {
  8.     for (int i = 0; i < n; i++) {
  9.         for (int j = 0; j < n; j++) {
  10.             if (a[j] > a[i]) {
  11.                 int tmp = a[i];
  12.                 a[i] = a[j];
  13.                 a[j] = tmp;
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19. int main() {
  20.     int a[100], b[100], n = 5;
  21.     bool flag = true;
  22.     for (int i = 0; i < n; i++)
  23.         cin >> a[i];
  24.     for (int i = 0; i < n; i++)
  25.         cin >> b[i];
  26.     arraySort(a, n);
  27.     arraySort(b, n);
  28.     for (int i = 0; i < n; i++)
  29.         if (a[i] != b[i]) {
  30.             flag = false;
  31.             break;
  32.         }
  33.  
  34.     if (flag)
  35.         cout << "Sunt anagrame";
  36.     else cout << "Nu sunt anagrame";
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement