Guest User

Untitled

a guest
Jul 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.32 KB | None | 0 0
  1. #include "mercadoria.h"
  2.  
  3. #include "planeta.h"
  4.  
  5. #include "robo.h"
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <string.h>
  10.  
  11. #include <stdlib.h>
  12.  
  13.  
  14.  
  15.  
  16.  
  17. void programa() {
  18.  
  19.     char comando [1000]= {'\0'};
  20.  
  21.     int matrizCompras[12][6];
  22.  
  23.     int i=0,j=0;//linhas e colunas
  24.  
  25.     int aux;
  26.  
  27.     int comp=0;
  28.  
  29.  
  30.  
  31.     char *rept;//ponteiro que fara a repetiÁ„o
  32.  
  33.     char *pont0;//poteiro apos hifen
  34.  
  35.  
  36.  
  37. //=====limpando a matriz====//
  38.  
  39.     for(i=0; i<12; i++) {
  40.  
  41.         for(j=0; j<5; j++) {
  42.  
  43.             matrizCompras[i][j]=0;
  44.  
  45.         }
  46.  
  47.     }
  48.  
  49. //printf("TESTE");OK
  50.  
  51.     scanf("%s",comando);
  52.     strcat(comando, ";");
  53.     rept=comando;
  54.  
  55. //printf("%s 123",rept);OK
  56.  
  57.  
  58.  
  59.     while(strstr(rept,";")!=NULL) {
  60.  
  61.         if(strncmp(rept,"viaja",5)==0) {
  62.  
  63.             pont0=strchr(rept,'-');
  64.  
  65.             pont0 ++;
  66.  
  67.  
  68.  
  69.             if( (strncmp(pont0,"0",1)==0)||(strncmp(pont0,"1",1)==0)||(strncmp(pont0,"2",1)==0)||
  70.  
  71.                     (strncmp(pont0,"3",1)==0)||(strncmp(pont0,"4",1)==0)||(strncmp(pont0,"5",1)==0)||
  72.  
  73.                     (strncmp(pont0,"6",1)==0)||(strncmp(pont0,"7",1)==0)||(strncmp(pont0,"8",1)==0)||
  74.  
  75.                     (strncmp(pont0,"9",1)==0)||(strncmp(pont0,"10",2)==0)||(strncmp(pont0,"11",2)==0) )
  76.  
  77.             {
  78.  
  79.                 aux=atoi(pont0);
  80.  
  81.                 i=aux;
  82.  
  83.             }
  84.  
  85.             else if(strncmp(pont0,"-1",2)==0) {
  86.  
  87.                 i=12;
  88.  
  89.             }
  90.  
  91.             else if(strncmp(pont0,"Mantor",6)==0) {
  92.  
  93.                 i=0;
  94.  
  95.             }
  96.  
  97.             else if (strncmp(pont0,"Zintor",6)==0) {
  98.  
  99.                 i=1;
  100.  
  101.             }
  102.  
  103.             else if (strncmp(pont0,"Asdropolis",10)==0) {
  104.  
  105.                 i=2;
  106.  
  107.             }
  108.  
  109.             else if (strncmp(pont0,"Zeta",4)==0) {
  110.  
  111.                 i=3;
  112.  
  113.             }
  114.  
  115.             else if (strncmp(pont0,"Bantor",6)==0) {
  116.  
  117.                 i=4;
  118.  
  119.             }
  120.  
  121.             else if (strncmp(pont0,"Tander",6)==0) {
  122.  
  123.                 i=5;
  124.  
  125.             }
  126.  
  127.             else if (strncmp(pont0,"Nova",4)==0) {
  128.  
  129.                 i=6;
  130.  
  131.             }
  132.  
  133.             else if (strncmp(pont0,"Pindora",7)==0) {
  134.  
  135.                 i=7;
  136.  
  137.             }
  138.  
  139.             else if (strncmp(pont0,"Castor",6)==0) {
  140.  
  141.                 i=8;
  142.  
  143.             }
  144.  
  145.             else if (strncmp(pont0,"Ra",2)==0) {
  146.  
  147.                 i=9;
  148.  
  149.             }
  150.  
  151.             else if (strncmp(pont0,"Re",2)==0) {
  152.  
  153.                 i=10;
  154.  
  155.             }
  156.  
  157.             else if (strncmp(pont0,"Ri",2)==0) {
  158.  
  159.                 i=11;
  160.  
  161.             }
  162.  
  163.             else if (strncmp(pont0,"Nada",4)==0) {
  164.  
  165.                 i=12;
  166.  
  167.             }
  168.  
  169.             rept=strchr(rept,';');
  170.  
  171.             rept++;
  172.  
  173.         }//viaja
  174.  
  175.  
  176.  
  177.  
  178.  
  179.         else if (strncmp(rept,"indica",6)==0) {
  180.  
  181.             pont0=strchr(rept,'-');
  182.  
  183.             pont0 ++;
  184.  
  185.             if((strncmp(pont0,"0",1)==0)||(strncmp(pont0,"cabeca",6)==0)) {
  186.  
  187.                 j=0;
  188.  
  189.             }
  190.  
  191.             else if((strncmp(pont0,"1",1)==0)||(strncmp(pont0,"corpo",5)==0)) {
  192.  
  193.                 j=1;
  194.  
  195.             }
  196.  
  197.             else if((strncmp(pont0,"2",1)==0)||(strncmp(pont0,"braco",5)==0)) {
  198.  
  199.                 j=2;
  200.  
  201.             }
  202.  
  203.             else if((strncmp(pont0,"3",1)==0)||(strncmp(pont0,"perna",5)==0)) {
  204.  
  205.                 j=3;
  206.  
  207.             }
  208.  
  209.             else if((strncmp(pont0,"4",1)==0)||(strncmp(pont0,"robo",4)==0)) {
  210.  
  211.                 j=4;
  212.  
  213.             }
  214.  
  215.             else if((strncmp(pont0,"-1",2)==0)||(strncmp(pont0,"nada",4)==0)) {
  216.  
  217.                 j=5;
  218.  
  219.             }
  220.  
  221.             rept=strchr(rept,';');
  222.  
  223.             rept ++;
  224.  
  225.         }// indica
  226.  
  227.  
  228.  
  229.         else if(strncmp(rept,"compra",6)==0) {
  230.  
  231.             pont0=strchr(rept,'-');
  232.  
  233.             pont0 ++;
  234.  
  235.             comp=atoi(pont0);
  236.  
  237.             matrizCompras[i][j]+=comp;//mesmas mercadorias sao somadas // EU MUDEI ISSO AQUI. o matrizCompras[i][j] tem a quantidade que já foi confirmada de ser comprada até o momento (começa em 0), e o comp adiciona mais uma quantidade recente.
  238.             //printf("%d",matrizCompras[i][j]);
  239.  
  240.  
  241.             rept=strchr(rept,';');
  242.  
  243.             rept ++;
  244.  
  245.         }//compra
  246.  
  247.  
  248.  
  249.     }// repetiÁao while
  250.  
  251.     //printf("AAA"); PROBLEMAS NO FOR
  252.  
  253.     for(i=0; i<12; i++) {
  254.         // Verifica se há realmente alguma coisa para ser comprada no planeta i.
  255.         int algoParaComprar = 0;
  256.         for(j = 0; j<5; j++) {
  257.             if(matrizCompras[i][j]>0) { // se > 0 quer dizer que há algo para ser comprado.
  258.                 if(i>0) viaja(i); //Como o planeta inicial é mantor, ele não faz viaja(0); Só
  259.                 algoParaComprar=1; // confirma que há algo para ser comprado, o que permite acessar o if logo abaixo.
  260.                 break;
  261.             }
  262.         }
  263.  
  264.         if(algoParaComprar==1) { // tem algo para comprar, então vamos comprar.
  265.             for(j=0; j<5; j++) {
  266.                 if(matrizCompras[i][j]>0) { // Nem todas as mercadorias precisam ser compradas, apenas aquelas que tem quantidade > 0
  267.  
  268.                     indicaMercadoria(j);
  269.                     compraMercadoria(matrizCompras[i][j]); // o matrizCompras[i][j] tem a quantidade que precisa ser comprada.
  270.                      //Indica e compra, simples
  271.  
  272.                 }
  273.  
  274.             }
  275.         }
  276.  
  277.  
  278.     }
  279.  
  280.  
  281.  
  282.  
  283.  
  284. }//fim do programa
Add Comment
Please, Sign In to add comment