Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #define MAX_MEGA_PIXELS 2
- #define MAX_PARTICIPANTES 500
- typedef char Texto[100];
- typedef struct {
- int id;
- Texto titulo;
- Texto autor;
- Texto tamano;
- Texto puntuacion;
- int visitas;
- } Fotografia;
- int llenaInformacionFotos (Fotografia f[MAX_PARTICIPANTES]) {
- int participantes,i,j,puntos;
- char cadena_test[50];
- 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"};
- fgets (cadena_test,50,stdin);
- srand (cadena_test[5]-'0');
- participantes = rand()%MAX_PARTICIPANTES;
- for (i=0;i<participantes;i++) {
- f[i].id = rand()%1000;
- strcpy(f[i].titulo,frases[rand()%10]);
- sprintf(f[i].autor,"%c%c%c%c%c",'a'+rand()%26,'a'+rand()%26,'a'+rand()%26,'a'+rand()%26,'a'+rand()%26);
- sprintf(f[i].tamano,"%dx%d",rand()%2000+500,rand()%2000+500);
- puntos = rand()%5+1;
- strcpy(f[j].puntuacion,"");
- for (j=0;j<puntos;j++) strcat(f[i].puntuacion,"*");
- f[i].visitas = rand()%1000;
- }
- return participantes;
- }
- int cumpleTamano(Fotografia foto){
- int h=0, w=0, i, m=1, total, k=1;
- for(i=0; foto.tamano[i] != 'x'; i++){
- }
- for(int j=(i-1); j>=0; j--){
- h = h + (foto.tamano[j] -'0')*m;
- m *= 10;
- }
- for(m=(strlen(foto.tamano) - 1); m>i; m--){
- w = w + (foto.tamano[m] - '0')*k;
- k *= 10;
- }
- total = w*h;
- if(MAX_MEGA_PIXELS*1000000 >= total){
- return 0;
- }else{
- return 1;
- }
- }
- int buscaGanador (Fotografia fotos[], int participantes){
- int estrelles=0, estrellesGrans=0, idGuanyador;
- for(int i=0; i<participantes; i++){
- if(cumpleTamano(fotos[i]) == 0){
- for(int j=0; j<5; j++){
- if(fotos[i].puntuacion[j] != '\0'){
- estrelles++;
- }else{
- j=5;
- }
- }
- if(estrelles > estrellesGrans){
- estrellesGrans = estrelles;
- idGuanyador = i;
- }
- if(estrelles == estrellesGrans){
- if(fotos[idGuanyador].visitas < fotos[i].visitas){
- idGuanyador = i;
- }
- }
- }
- }
- return idGuanyador;
- }
- void confeccionaDatosFoto (Fotografia fotos, Texto datos){
- char aux[] = "#";
- char id[15];
- sprintf(id, "%d", fotos.id);
- strcat(datos, fotos.titulo);
- strcat(datos, aux);
- strcat(datos, id);
- strcat(datos, aux);
- sprintf(id, "%lu", strlen(fotos.puntuacion)-1);
- strcat(datos, id);
- strcat(datos, fotos.tamano);
- }
- int main () {
- Fotografia fotos[MAX_PARTICIPANTES];
- int participantes, casilla_ganador;
- Texto datos;
- participantes = llenaInformacionFotos (fotos);
- casilla_ganador = buscaGanador (fotos, participantes);
- printf ("And the winner is: %s\n",fotos[casilla_ganador].autor);
- confeccionaDatosFoto (fotos[casilla_ganador], datos);
- printf ("La foto tiene la siguiente descripción: %s\n", datos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement