Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. #define MAX_MEGA_PIXELS 2
  7. #define MAX_PARTICIPANTES 500
  8.  
  9. typedef char Texto[100];
  10.  
  11. typedef struct {
  12. int id;
  13. Texto titulo;
  14. Texto autor;
  15. Texto tamano;
  16. Texto puntuacion;
  17. int visitas;
  18. } Fotografia;
  19.  
  20. int llenaInformacionFotos (Fotografia f[MAX_PARTICIPANTES]) {
  21. int participantes,i,j,puntos;
  22. char cadena_test[50];
  23. Texto frases[10] = {"En el examen de cálculo","La mejor foto","Foto a oscuras","Voy a aprobar","La mejor cámara de fotos","Con luces y a lo loco","El jardín del edén","Alea jacta est","Viva la programación","Salvador por la campana"};
  24.  
  25. fgets (cadena_test,50,stdin);
  26.  
  27. srand (cadena_test[5]-'0');
  28.  
  29. participantes = rand()%MAX_PARTICIPANTES;
  30.  
  31. for (i=0;i<participantes;i++) {
  32. f[i].id = rand()%1000;
  33. strcpy(f[i].titulo,frases[rand()%10]);
  34. sprintf(f[i].autor,"%c%c%c%c%c",'a'+rand()%26,'a'+rand()%26,'a'+rand()%26,'a'+rand()%26,'a'+rand()%26);
  35. sprintf(f[i].tamano,"%dx%d",rand()%2000+500,rand()%2000+500);
  36. puntos = rand()%5+1;
  37. strcpy(f[j].puntuacion,"");
  38. for (j=0;j<puntos;j++) strcat(f[i].puntuacion,"*");
  39. f[i].visitas = rand()%1000;
  40. }
  41. return participantes;
  42. }
  43.  
  44. int cumpleTamano(Fotografia foto){
  45. int h=0, w=0, i, m=1, total, k=1;
  46.  
  47. for(i=0; foto.tamano[i] != 'x'; i++){
  48.  
  49. }
  50. for(int j=(i-1); j>=0; j--){
  51. h = h + (foto.tamano[j] -'0')*m;
  52. m *= 10;
  53.  
  54. }
  55.  
  56. for(m=(strlen(foto.tamano) - 1); m>i; m--){
  57. w = w + (foto.tamano[m] - '0')*k;
  58. k *= 10;
  59. }
  60.  
  61. total = w*h;
  62. if(MAX_MEGA_PIXELS*1000000 >= total){
  63. return 0;
  64. }else{
  65. return 1;
  66. }
  67. }
  68.  
  69. int buscaGanador (Fotografia fotos[], int participantes){
  70. int estrelles=0, estrellesGrans=0, idGuanyador;
  71.  
  72. for(int i=0; i<participantes; i++){
  73. if(cumpleTamano(fotos[i]) == 0){
  74. for(int j=0; j<5; j++){
  75. if(fotos[i].puntuacion[j] != '\0'){
  76. estrelles++;
  77. }else{
  78. j=5;
  79. }
  80. }
  81. if(estrelles > estrellesGrans){
  82. estrellesGrans = estrelles;
  83. idGuanyador = i;
  84. }
  85. if(estrelles == estrellesGrans){
  86. if(fotos[idGuanyador].visitas < fotos[i].visitas){
  87. idGuanyador = i;
  88. }
  89. }
  90. }
  91.  
  92. }
  93. return idGuanyador;
  94. }
  95. void confeccionaDatosFoto (Fotografia fotos, Texto datos){
  96. char aux[] = "#";
  97. char id[15];
  98. sprintf(id, "%d", fotos.id);
  99. strcat(datos, fotos.titulo);
  100. strcat(datos, aux);
  101.  
  102. strcat(datos, id);
  103. strcat(datos, aux);
  104. sprintf(id, "%lu", strlen(fotos.puntuacion)-1);
  105. strcat(datos, id);
  106. strcat(datos, fotos.tamano);
  107. }
  108.  
  109. int main () {
  110.  
  111. Fotografia fotos[MAX_PARTICIPANTES];
  112. int participantes, casilla_ganador;
  113. Texto datos;
  114.  
  115. participantes = llenaInformacionFotos (fotos);
  116. casilla_ganador = buscaGanador (fotos, participantes);
  117. printf ("And the winner is: %s\n",fotos[casilla_ganador].autor);
  118. confeccionaDatosFoto (fotos[casilla_ganador], datos);
  119. printf ("La foto tiene la siguiente descripción: %s\n", datos);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement