Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mercadoria.h"
- #include "planeta.h"
- #include "robo.h"
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void programa() {
- char comando [1000]= {'\0'};
- int matrizCompras[12][6];
- int i=0,j=0;//linhas e colunas
- int aux;
- int comp=0;
- char *rept;//ponteiro que fara a repetiÁ„o
- char *pont0;//poteiro apos hifen
- //=====limpando a matriz====//
- for(i=0; i<12; i++) {
- for(j=0; j<5; j++) {
- matrizCompras[i][j]=0;
- }
- }
- //printf("TESTE");OK
- scanf("%s",comando);
- strcat(comando, ";");
- rept=comando;
- //printf("%s 123",rept);OK
- while(strstr(rept,";")!=NULL) {
- if(strncmp(rept,"viaja",5)==0) {
- pont0=strchr(rept,'-');
- pont0 ++;
- if( (strncmp(pont0,"0",1)==0)||(strncmp(pont0,"1",1)==0)||(strncmp(pont0,"2",1)==0)||
- (strncmp(pont0,"3",1)==0)||(strncmp(pont0,"4",1)==0)||(strncmp(pont0,"5",1)==0)||
- (strncmp(pont0,"6",1)==0)||(strncmp(pont0,"7",1)==0)||(strncmp(pont0,"8",1)==0)||
- (strncmp(pont0,"9",1)==0)||(strncmp(pont0,"10",2)==0)||(strncmp(pont0,"11",2)==0) )
- {
- aux=atoi(pont0);
- i=aux;
- }
- else if(strncmp(pont0,"-1",2)==0) {
- i=12;
- }
- else if(strncmp(pont0,"Mantor",6)==0) {
- i=0;
- }
- else if (strncmp(pont0,"Zintor",6)==0) {
- i=1;
- }
- else if (strncmp(pont0,"Asdropolis",10)==0) {
- i=2;
- }
- else if (strncmp(pont0,"Zeta",4)==0) {
- i=3;
- }
- else if (strncmp(pont0,"Bantor",6)==0) {
- i=4;
- }
- else if (strncmp(pont0,"Tander",6)==0) {
- i=5;
- }
- else if (strncmp(pont0,"Nova",4)==0) {
- i=6;
- }
- else if (strncmp(pont0,"Pindora",7)==0) {
- i=7;
- }
- else if (strncmp(pont0,"Castor",6)==0) {
- i=8;
- }
- else if (strncmp(pont0,"Ra",2)==0) {
- i=9;
- }
- else if (strncmp(pont0,"Re",2)==0) {
- i=10;
- }
- else if (strncmp(pont0,"Ri",2)==0) {
- i=11;
- }
- else if (strncmp(pont0,"Nada",4)==0) {
- i=12;
- }
- rept=strchr(rept,';');
- rept++;
- }//viaja
- else if (strncmp(rept,"indica",6)==0) {
- pont0=strchr(rept,'-');
- pont0 ++;
- if((strncmp(pont0,"0",1)==0)||(strncmp(pont0,"cabeca",6)==0)) {
- j=0;
- }
- else if((strncmp(pont0,"1",1)==0)||(strncmp(pont0,"corpo",5)==0)) {
- j=1;
- }
- else if((strncmp(pont0,"2",1)==0)||(strncmp(pont0,"braco",5)==0)) {
- j=2;
- }
- else if((strncmp(pont0,"3",1)==0)||(strncmp(pont0,"perna",5)==0)) {
- j=3;
- }
- else if((strncmp(pont0,"4",1)==0)||(strncmp(pont0,"robo",4)==0)) {
- j=4;
- }
- else if((strncmp(pont0,"-1",2)==0)||(strncmp(pont0,"nada",4)==0)) {
- j=5;
- }
- rept=strchr(rept,';');
- rept ++;
- }// indica
- else if(strncmp(rept,"compra",6)==0) {
- pont0=strchr(rept,'-');
- pont0 ++;
- comp=atoi(pont0);
- 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.
- //printf("%d",matrizCompras[i][j]);
- rept=strchr(rept,';');
- rept ++;
- }//compra
- }// repetiÁao while
- //printf("AAA"); PROBLEMAS NO FOR
- for(i=0; i<12; i++) {
- // Verifica se há realmente alguma coisa para ser comprada no planeta i.
- int algoParaComprar = 0;
- for(j = 0; j<5; j++) {
- if(matrizCompras[i][j]>0) { // se > 0 quer dizer que há algo para ser comprado.
- if(i>0) viaja(i); //Como o planeta inicial é mantor, ele não faz viaja(0); Só
- algoParaComprar=1; // confirma que há algo para ser comprado, o que permite acessar o if logo abaixo.
- break;
- }
- }
- if(algoParaComprar==1) { // tem algo para comprar, então vamos comprar.
- for(j=0; j<5; j++) {
- if(matrizCompras[i][j]>0) { // Nem todas as mercadorias precisam ser compradas, apenas aquelas que tem quantidade > 0
- indicaMercadoria(j);
- compraMercadoria(matrizCompras[i][j]); // o matrizCompras[i][j] tem a quantidade que precisa ser comprada.
- //Indica e compra, simples
- }
- }
- }
- }
- }//fim do programa
Add Comment
Please, Sign In to add comment