Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. i = inicio;
  2. j = fim;
  3.  
  4. meio = (int) ((i + j) / 2);
  5. pivo = vetor[meio];
  6.  
  7. do{
  8. while (vetor[i].valor < pivo.valor) i = i + 1;
  9. while (vetor[j].valor > pivo.valor) j = j - 1;
  10.  
  11. if(i <= j){
  12. aux = vetor[i];
  13. vetor[i] = vetor[j];
  14. vetor[j] = aux;
  15. i = i + 1;
  16. j = j - 1;
  17. }
  18. }while(j > i);
  19.  
  20. if(inicio < j) ordenar(vetor, inicio, j);
  21. if(i < fim) ordenar(vetor, i, fim);
  22.  
  23. cout << fixed << setprecision(3);
  24. int n, x, y, cidade = 1, *pessoas, totalPessoas;
  25. Lista *consumo;
  26. double consumoMedio, consumoTotal;
  27.  
  28. bool flag = false;
  29.  
  30. while(cin >> n) {
  31.  
  32. if(n == 0)
  33. break;
  34. else if(flag)
  35. cout << endl;
  36.  
  37.  
  38. cout << "Cidade# " << cidade << endl;
  39.  
  40. consumo = new Lista[n];
  41. pessoas = new int[n];
  42. consumoTotal = 0;
  43. totalPessoas = 0;
  44.  
  45. for(int i = 0; i < n; i++){
  46. cin >> x;
  47. totalPessoas += x;
  48.  
  49. cin >> y;
  50. consumoTotal += y;
  51.  
  52. pessoas[i] = x;
  53. consumo[i].valor = y/x;
  54. consumo[i].next = &pessoas[i];
  55. }
  56.  
  57. ordenar(consumo, 0, n-1);
  58.  
  59. for(int i = 0; i < n; i++) {
  60. cout << *consumo[i].next << "-" << consumo[i].valor;
  61. if(i == n-1)
  62. cout << endl;
  63. else
  64. cout << " ";
  65. }
  66.  
  67. double int_part;
  68. int frac_part;
  69. frac_part = (int) (modf ((double)consumoTotal/totalPessoas, &int_part) *100);
  70.  
  71. if(frac_part < 10)
  72. cout << "Consumo medio: " << (int)int_part << ".0" << (int)frac_part << " m3.n";
  73. else
  74. cout << "Consumo medio: " << (int)int_part << "." << (int)frac_part << " m3.n";
  75.  
  76. flag = true;
  77.  
  78. cidade++;
  79.  
  80. delete consumo;
  81. delete pessoas;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement