Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int FILAS = 100;
  6. const int COLUMNAS = 100;
  7.  
  8. void asignacion(int m[FILAS][COLUMNAS],int escanyos,int partidos);
  9.  
  10. int main()
  11. {
  12. int partidos;
  13. int escanyos;
  14. int votos;
  15.  
  16. cout << "Escaños" << endl;
  17. cout << "Introduzca el numero de partidos que han participado en las elecciones" << endl;
  18. cin >> partidos;
  19. cout << "Introduzca el numero de escaños a repartir" << endl;
  20. cin >> escanyos;
  21.  
  22. int datos[FILAS][COLUMNAS] = {0};
  23.  
  24. for(int i=0;i<escanyos;i++){
  25. cout << "Introducir el numero de votos para el partido " << i+1 << endl;
  26. cin >> votos;
  27. for(int f=0;f<partidos;f++){
  28. datos[i][f] = votos;
  29. }
  30. }
  31. asignacion(datos,escanyos,partidos);
  32.  
  33. for(int j=0;j<partidos;j++){
  34. cout << datos[escanyos+1][j] << " ";
  35. }
  36.  
  37. return 0;
  38. }
  39.  
  40. void asignacion(int m[FILAS][COLUMNAS],int escanyos,int partidos){
  41. int num_partido=0;
  42. int maximo=0;
  43. for(int i=0;i<escanyos;i++){
  44. for(int j=0;j<partidos;j++){
  45. m[i][j]=m[i][j]/(m[escanyos][j]+1);
  46.  
  47. if(m[i][j]>=maximo){
  48. maximo = m[i][j];
  49. num_partido = j;
  50. }
  51. }
  52. //Termino de recorrer la fila, inicializo todo y asigno +1 al partido
  53. maximo = 0;
  54. m[escanyos+1][num_partido]++;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement