Advertisement
Guest User

Q2

a guest
Nov 10th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int t;
  9.     cin >> t;
  10.     while (t--)
  11.     {
  12.         int n;
  13.         cin >> n;
  14.         long long arr[n];
  15.         for (int i = 0; i < n; i++)
  16.         {
  17.             cin >> arr[i];
  18.         }
  19.         sort(arr, arr + n);
  20.         int pos = 1;
  21.         for (int i = 0; i < n;)
  22.         {
  23.             cout << arr[i++];
  24.             while (i<n && arr[i] == arr[i - 1])
  25.             {
  26.                 cout << ' ' << arr[i++];
  27.             }
  28.             cout << '\n';
  29.             pos++;
  30.             if (pos > 3)
  31.                 break;
  32.         }
  33.         cout << '\n';
  34.     }
  35.     return 0;
  36. }
Tags: CDVR3.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement