fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. pair<int, int> t[1001];
  6.  
  7. int main() {
  8. int n;
  9. cin >> n;
  10. for (int i = 1; i <= n; i++) {
  11. int a;
  12. cin>>a;
  13. t[i] = make_pair(a, i);
  14. }
  15. // use block-sort if needed
  16. int len = 0;
  17. for (int i = n; i >= 1; i--) {
  18. if (t[i].first != t[i - 1].first) {
  19. len++;
  20. } else {
  21. swap(t[i], t[i + len]);
  22. }
  23. }
  24. sort(t + 1, t + 1 + len);
  25. for (int i = 1; i <= n; i++) {
  26. cout<<"("<<t[i].first<<", "<<t[i].second<<") ";
  27. }
  28. cout<<endl;
  29. }
Success #stdin #stdout 0s 3312KB
stdin
16
1 1 1 1 1 2 2 2 2 3 3 4 4 4 4 4 
stdout
(1, 1) (2, 6) (3, 10) (4, 12) (1, 2) (1, 3) (1, 4) (1, 5) (2, 7) (2, 8) (2, 9) (3, 11) (4, 13) (4, 14) (4, 15) (4, 16)