Advertisement
Guest User

Untitled

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