Advertisement
BatedCrayon

Sort_Indici #1911 | Pbinfo

Apr 26th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #define NMAX 101
  4.  
  5. using namespace std;
  6.  
  7. //By BatedCrayon
  8.  
  9. struct date{
  10.     int numar;
  11.     int poz;
  12. }v[NMAX];
  13.  
  14. int n,i,j;
  15.  
  16.  
  17. void Citire()
  18. {
  19.     cin>>n;
  20.     //Citim numarul si ii stocam pozitia
  21.     for(i=1; i<=n; i++)
  22.     {
  23.         cin>>v[i].numar;
  24.         v[i].poz=i;
  25.     }
  26. }
  27.  
  28. void Sorting()
  29. {
  30.     for(i=1; i<=n-1; i++)
  31.         for(j=i+1; j<=n; j++)
  32.         {
  33.             if(v[i].numar>v[j].numar)
  34.                 swap(v[i],v[j]);
  35.             else
  36.             {
  37.                 //Daca numarul este egal comparam pozitiile
  38.                 if(v[i].poz>v[j].poz)
  39.                     swap(v[i],v[j]);
  40.             }
  41.         }
  42.  
  43. }
  44.  
  45. void Afisare()
  46. {
  47.     //Afiseaza numarul si pozitia
  48.     for(i=1; i<=n; i++)
  49.         cout<<v[i].numar<<" "<<v[i].poz<<" ";
  50. }
  51.  
  52. int main()
  53. {
  54.     Citire();
  55.     Sorting();
  56.     Afisare();
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement