Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #define NMAX 101
- using namespace std;
- //By BatedCrayon
- struct date{
- int numar;
- int poz;
- }v[NMAX];
- int n,i,j;
- void Citire()
- {
- cin>>n;
- //Citim numarul si ii stocam pozitia
- for(i=1; i<=n; i++)
- {
- cin>>v[i].numar;
- v[i].poz=i;
- }
- }
- void Sorting()
- {
- for(i=1; i<=n-1; i++)
- for(j=i+1; j<=n; j++)
- {
- if(v[i].numar>v[j].numar)
- swap(v[i],v[j]);
- else
- {
- //Daca numarul este egal comparam pozitiile
- if(v[i].poz>v[j].poz)
- swap(v[i],v[j]);
- }
- }
- }
- void Afisare()
- {
- //Afiseaza numarul si pozitia
- for(i=1; i<=n; i++)
- cout<<v[i].numar<<" "<<v[i].poz<<" ";
- }
- int main()
- {
- Citire();
- Sorting();
- Afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement