Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(void)
  8. {
  9. int k, n, c;
  10. c = 1;
  11. while(n != 0)
  12. {
  13. cout << "n: ";
  14. cin >> n;
  15. cout << "k: ";
  16. cin >> k;
  17.  
  18.  
  19. vector<string> nome(n);
  20. pair<string, int> ind[n];
  21. pair<string, int> aux;
  22.  
  23. for(int i = 0; i < n; i++)
  24. {
  25. cin >> nome[i];
  26. ind[i].first = nome[i];
  27. ind[i].second = i;
  28. }
  29.  
  30. for(int i=0; i<=k; i++)
  31. {
  32. for (int j = (i+1); j <= k; j++)
  33. {
  34.  
  35. if (ind[j] < ind[i])
  36. {
  37. aux = ind[i];
  38. ind[i] = ind[j];
  39. ind[j] = aux;
  40. }
  41. }
  42. }
  43. cout << "Instancia " << c++ << '\n';
  44. for(int i = 0; i < n; ++i)
  45. cout << ind[i].first << ' ';
  46. cout << "\n\n";
  47. }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement