Advertisement
weldisalves

tarefa03.c

Sep 7th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define MAX 6
  6. #define MAX_CARACTER 30
  7. #define MAX_LOTERICAS 90
  8.  
  9. typedef struct{
  10.     int codAposta;
  11.     int codLoterica;
  12.     char dataHora[MAX_CARACTER];
  13.     int qtdeNumerosApostados;
  14.     int *numerosApostados;
  15.     }Aposta;
  16.  
  17. typedef struct no{
  18.     Aposta info;
  19.     struct no *prox;
  20.     }No;
  21.  
  22. typedef struct{
  23.     int qtde;
  24.     No *inicio;
  25.     }Lista;
  26.  
  27. typedef struct{
  28.     char estado[3];
  29.     int codEstado;
  30.     }Loterica;
  31.  
  32. //prototipos
  33. void sorteados(int numerosSorteados[]);
  34. void inicia(Lista *lista);
  35. void carregaAposta(Lista *lista);
  36. void carregaLotericas (Loterica *loterica);
  37. int resultadoDaAposta(int *vet, int quant,int numerosSorteados[]);
  38. void resultados(Lista *lista,No *aposta);
  39. void megaSena(Lista *lista,Lista *sena,int sorteados[]);
  40.  
  41. int main()
  42. {
  43.     Lista *lista=(Lista *)malloc(sizeof(Lista));
  44.     Lista *sena=(Lista *)malloc(sizeof(Lista));
  45.     Lista *quina=(Lista *)malloc(sizeof(Lista));
  46.     Lista *quadra=(Lista *)malloc(sizeof(Lista));
  47.  
  48.     Loterica *loterica=(Loterica*)malloc(sizeof(Loterica)*MAX_LOTERICAS);
  49.  
  50.     int numerosSorteados[MAX];
  51.  
  52.     inicia(lista);
  53.     inicia(sena);
  54.     inicia(quina);
  55.     inicia(quadra);
  56.  
  57.     carregaLotericas(loterica);
  58.     sorteados(numerosSorteados);
  59.     carregaAposta(lista);
  60.  
  61.     megaSena(lista,sena,numerosSorteados);
  62.  
  63.  
  64.  
  65.  
  66.     getch();
  67.     return 0;
  68. }
  69.  
  70. void sorteados(int numerosSorteados[])
  71. {
  72.     FILE *arquivo = fopen("arquivoentrada.txt","r");
  73.     while(!feof(arquivo))
  74.     {
  75.         fscanf(arquivo,"%d",&*numerosSorteados);
  76.         numerosSorteados++;
  77.     }
  78.     /*while(scanf("%d",&*numerosSorteados)!=EOF)
  79.     {
  80.         numerosSorteados++;
  81.     }*/
  82.  
  83.     fclose(arquivo);
  84. }
  85.  
  86. void inicia(Lista *lista)
  87. {
  88.     lista->qtde = 0;
  89.     lista->inicio = NULL;
  90. }
  91.  
  92. void carregaAposta(Lista *lista)
  93. {
  94.     FILE *arquivo = fopen("apostas.txt","r+");
  95.     No *p = lista->inicio;
  96.     int i;
  97.  
  98.     if(!arquivo)
  99.     {
  100.         printf("\n ERRO NO ARQUIVO");
  101.         return;
  102.     }
  103.  
  104.     while(!feof(arquivo))
  105.     {
  106.         p=(No*)malloc(sizeof(No));
  107.  
  108.         fscanf(arquivo,"%d %d %s %d",&p->info.codAposta,&p->info.codLoterica,p->info.dataHora,&p->info.qtdeNumerosApostados);
  109.  
  110.         p->info.numerosApostados=(int*)malloc(sizeof(int)*p->info.qtdeNumerosApostados);
  111.  
  112.         for(i=0;i<p->info.qtdeNumerosApostados;i++)
  113.         {
  114.             fscanf(arquivo,"%d",&p->info.numerosApostados[i]);
  115.         }
  116.  
  117.         lista->qtde++;
  118.         p->prox=NULL;
  119.         p=p->prox;
  120.     }
  121.  
  122.     fclose(arquivo);
  123. }
  124.  
  125. void carregaLotericas (Loterica *loterica)
  126. {
  127.     FILE *arquivo = fopen("lotericas.txt","r+");
  128.  
  129.     if(!arquivo)
  130.     {
  131.         printf("\n ERRO NO ARQUIVO LOTERICAS.TXT");
  132.         return;
  133.     }
  134.  
  135.     while(!feof(arquivo))
  136.     {
  137.         fscanf(arquivo,"%d %s",&loterica->codEstado,loterica->estado);
  138.         loterica++;
  139.     }
  140.  
  141.     fclose(arquivo);
  142. }
  143.  
  144. int resultadoDaAposta(int *vet, int quant,int numerosSorteados[])
  145. {
  146.     int i,cont=0,j;
  147.     for(i=0;i<MAX;i++)
  148.     {
  149.         for(j=0;j<quant;j++)
  150.         {
  151.             if(vet[j]==numerosSorteados[i]) cont++;
  152.         }
  153.     }
  154.  
  155.     return cont;
  156. }
  157.  
  158. void megaSena(Lista *lista,Lista *sena,int sorteados[])
  159. {
  160.     No *p=lista->inicio;
  161.     No *seis=sena->inicio;
  162.     No *aux;
  163.  
  164.     int i=0;
  165.  
  166.     do{
  167.             if(resultadoDaAposta(p->info.numerosApostados,p->info.qtdeNumerosApostados,sorteados)==6)
  168.             {
  169.                 seis=(No *)malloc(sizeof(No));
  170.                 seis=p;printf("\n aki");getch();
  171.                 seis->prox=NULL;printf("\n aki");getch();
  172.                 seis=seis->prox;
  173.             }
  174.             p=p->prox;
  175.  
  176.         i++;
  177.     }while(i<9000);
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement