int main() { char in[TAM_MAX_EXPR+2], res[TAM_MAX_EXPR+1]; Erro erro; ArvBin arv; while (leExpr(in)>0) { erro = InArv(in,&arv); printf("Infixa: %s\n", in); if (erro.codigoErro == EXPR_VALIDA) { ArvPre(arv,res); /* para ser usado em depuração: basta descomentar */ /* despejaArv(arv); */ printf("Prefixa: %s\n",res); ArvPos(arv,res); printf("Posfixa: %s\n\n",res); } else mostraErro(erro); printf("\n"); LiberaArv(arv); } /* Verifica se foram liberados todos os blocos alocados */ bapply(bprint); printf("Processamento terminado\n"); return 0; } /* main */
int main() { char op; scanf("%c\n", &op); switch (op) { case ('+'): soma(); break; case ('*'): multiplicacao(); break; case ('/'): divide(); break; case ('G'): godel(); break; default: printf("Operacao invalida\n"); break; } bapply(bprint); return 0; }
int main() { Grafo g; int n; int u, v, p, r; int *dist; int achou; /* Número de vértices */ if ((scanf("%d",&n)!=1) || (n<0) || (n>TAM_MAX)) DadosErrados(); g = CriaGrafoVazio(n); if ((dist=MALLOC(sizeof(int)*n))==NULL) { printf("Memória esgotada\n"); return 0; } /* Leitura de arestas */ while (1) { if (scanf("%d %d %d",&u,&v,&p)!=3) DadosErrados(); if (u==-1) break; if (AcrescentaAresta(g,u,v,p)!=CERTO) DadosErrados(); } /* break */ ImprimeGrafo(g); /* Aplicação do algoritmo de Dijkstra */ while (1) { if (scanf("%d",&r)!=1) DadosErrados(); if (r==-1) break; if ((r<0) || (r>=n)) DadosErrados(); printf("Caminhos mínimos a partir do vértice %d:\n",r); Dijkstra(g,r,dist); achou = 0; for (v=0; v<n; v++) { if ((v!=r) && (dist[v]!=INT_MAX)) { printf("%3d: %d\n",v,dist[v]); achou++; } } if (achou==0) printf(" nenhum\n"); } /* break */ LiberaGrafo(g); FREE(dist); bapply(bprint); printf("Processamento terminado\n"); return 0; } /* main */
// Make a popup dialog box PoreBoard::PoreBoard( QWidget * parent, const char * name ) : QDialog( parent, name, FALSE, WType_TopLevel ) { this->setCaption( "AViz: Set Pores" ); // Create a hboxlayout that will fill the first row hb1 = new QHBox( this, "hb1" ); // Create a label QLabel * poreL = new QLabel( hb1, "poreL" ); poreL->setText( " Type: "); // Create a combo box that will go into the // second column; entries in the combo box will // be made later poreCob = new QComboBox( FALSE, hb1, "poreSelection" ); // Define a callback for this combo box connect( poreCob, SIGNAL(activated(int)), SLOT(setPore()) ); // Create a placeholder QLabel * emptyL0 = new QLabel( hb1, "emptyL0" ); emptyL0->setText(""); // Add a check box button showPoreCb = new QCheckBox( hb1, "showPore" ); showPoreCb->setText( "Show Pores" ); showPoreCb->setChecked( TRUE ); // Define a callback for this toggle switch connect( showPoreCb, SIGNAL(clicked()), this, SLOT(adjustPore()) ); // Create a hboxlayout that will fill the next row hb2 = new QHBox( this, "hb2" ); // Add a label and color labels colorL = new QLabel( hb2, "colorL" ); colorL->setText( " Color: " ); colorLabel0 = new ColorLabel( hb2, "color0" ); colorLabel1 = new ColorLabel( hb2, "color1" ); colorLabel2 = new ColorLabel( hb2, "color2" ); colorLabel3 = new ColorLabel( hb2, "color3" ); colorLabel4 = new ColorLabel( hb2, "color4" ); colorLabel5 = new ColorLabel( hb2, "color5" ); colorLabel0->setFixedHeight( LABEL_HEIGHT ); colorLabel1->setFixedHeight( LABEL_HEIGHT ); colorLabel2->setFixedHeight( LABEL_HEIGHT ); colorLabel3->setFixedHeight( LABEL_HEIGHT ); colorLabel4->setFixedHeight( LABEL_HEIGHT ); colorLabel5->setFixedHeight( LABEL_HEIGHT ); colorLabel0->setColor( 1.0, 1.0, 1.0); colorLabel1->setColor( 1.0, 1.0, 1.0); colorLabel2->setColor( 1.0, 1.0, 1.0); colorLabel3->setColor( 1.0, 1.0, 1.0); colorLabel4->setColor( 1.0, 1.0, 1.0); colorLabel5->setColor( 1.0, 1.0, 1.0); // Add a push button colorButton = new QPushButton( hb2, "colorButton" ); colorButton->setText( "Set Color..." ); // Define a callback for this button QObject::connect( colorButton, SIGNAL(clicked()), this, SLOT(setColorCb( )) ); // Create a hboxlayout that will fill the next row sizeBox = new SizeBox( this, "sizeBox" ); // Create a hboxlayout that will fill the next row hb4 = new QHBox( this, "hb4" ); // Add radiobuttons and a label modeL = new QLabel( hb4, "modeL" ); modeL->setText( " Color Criterion: " ); colorMode = new QButtonGroup( 3, QGroupBox::Horizontal, hb4, "colorMode" ); colorMode0 = new QRadioButton( colorMode, "type" ); colorMode0->setText( "Type" ); colorMode1 = new QRadioButton( colorMode, "position" ); colorMode1->setText( "Position" ); colorMode2 = new QRadioButton( colorMode, "property" ); colorMode2->setText( "Property" ); colorMode3 = new QRadioButton( colorMode, "colorcode" ); colorMode3->setText( "ColorCode" ); colorMode->insert( colorMode0, 0 ); colorMode->insert( colorMode1, 1 ); colorMode->insert( colorMode2, 2 ); colorMode->insert( colorMode3, 3 ); // Define a callback for these radio buttons connect( colorMode, SIGNAL(clicked(int)), this, SLOT(adjustCriterion()) ); // Create hboxlayouts that will fill the next row; these // are shown only when appropriate positionBox = new PositionBox( this, "positionBox" ); propertyBox = new PropertyBox( this, "positionBox" ); codeBox = new CodeBox( this, "codeBox" ); typeColorNumberBox = new TypeColorNumberBox( this, "typeColorNumberBox", 2 ); // Create a box that will fill the next row lineTypeBox = new LineTypeBox( this, "lineTypeBox" ); // Create a hboxlayout that will fill the lowest row hb5 = new QHBox( this, "hb5" ); // Create a placeholder QLabel * emptyL1 = new QLabel( hb5, "emptyL1" ); // Create pushbuttons that will go into the lowest row QPushButton * done = new QPushButton( hb5, "done" ); done->setText( "Done" ); // Define a callback for that button QObject::connect( done, SIGNAL(clicked()), this, SLOT(bdone()) ); QPushButton * apply = new QPushButton( hb5, "apply" ); apply->setText( "Apply" ); // Define a callback for that button QObject::connect( apply, SIGNAL(clicked()), this, SLOT(bapply()) ); QPushButton * cancel = new QPushButton( hb5, "cancel" ); cancel->setText( "Cancel" ); // Define a callback for that button QObject::connect( cancel, SIGNAL(clicked()), this, SLOT(bcancel()) ); hb5->setStretchFactor( emptyL1, 10 ); // Clear the board pointer poreBox = NULL; // Clear the color board pointer cb = NULL; // Clear internal variables colors = 1; colorPosX = colorPosY = 0; showColorBoard = FALSE; poreRenderStyle = PLINE; renderQuality = LOW; // Set defaults appropriate for startup without data colorButton->setDisabled( TRUE ); sizeBox->setDisabled( TRUE ); modeL->setDisabled( TRUE ); colorMode->setDisabled( TRUE ); colorMode0->setChecked( TRUE ); // Build default layout this->buildLayout( TYPE ); }
int main() { char txt[TamMaxTexto]; char auxTxt[TamMaxTexto]; char bits[TamMaxComprimido]; int tamTxt, tamAuxTxt, numBits; /* Lê o texto de entrada */ if (!LeTexto(txt, &tamTxt)) { printf("Problemas com o arquivo de entrada\n"); return 0; } printf("\nTexto original:\n"); printf("--------------------------------------------------\n"); Escreve(txt,tamTxt); printf("--------------------------------------------------\n"); /* Inicializa estruturas */ if(ConstroiHuffman(txt, tamTxt)) { printf("\nÁrvore de Huffman:\n\n"); ImprimeHuffman(); } else { printf("\nNão foi possível construir a árvore\n"); return 0; } if (!Comprime(txt, tamTxt, bits, &numBits, TamMaxComprimido)) { printf("Problemas na compressão\n"); return 0; } printf("\nTexto comprimido:\n"); EscreveBits(bits, numBits); printf("\n"); if (!Descomprime(auxTxt,&tamAuxTxt,bits,numBits,TamMaxTexto)) { printf("Problemas na descompressão\n"); return 1; } printf("\nTexto descomprimido:\n"); printf("--------------------------------------------------\n"); Escreve(auxTxt, tamAuxTxt); printf("--------------------------------------------------\n"); if (tamTxt == tamAuxTxt && strncmp(txt,auxTxt,tamTxt)==0) printf("\nTextos idênticos\n"); else { printf("\nTextos diferentes\n"); return 0; } printf("\nTexto original: %d bytes\n", tamTxt); printf("Cadeia comprimida: %d bits (%d bytes)\n", numBits, numBits % 8 == 0 ? numBits/8 : numBits/8 + 1); printf("Média: %2.1f bits/caractere\n", (float)numBits/(float)tamTxt); LiberaHuffman(); /* Finalização */ int bch = bcheck(); /* Verifica liberação correta de memória dinâmica */ if (bch!=0) { printf("\n%d blocos de memória dinâmica não foram liberados:\n",bch); bapply(bprint); } else{ printf("\nA memória dinâmica foi totalmente liberada\n" ); } printf("\nProcessamento terminado\n"); return 0; }
int main() { Trie trie; Boolean fim = false; char *cadeia; char acao; do { cadeia = leLinha(&acao); switch(acao) { case 'c': case 'C': trie = CriaAD(); break; case '#': case ' ': break; case 'i': case 'I': if (!insereAD(trie,cadeia)) printf("A cadeia já ocorre na árvore\n"); break; case 'v': case 'V': if (consultaAD(trie,cadeia)) printf("A cadeia ocorre na árvore\n"); else printf("A cadeia não ocorre na árvore\n"); break; case 'r': case 'R': if (!removeAD(trie,cadeia)) printf("A cadeia não ocorre na árvore\n"); break; case 'p': case 'P': percorreAD(trie,visita); break; case 'n': case 'N': printf("Nos: %d\n",numNosAD(trie)); break; case 'a': case 'A': printf("Altura: %d\n",alturaAD(trie)); break; case 'k': case 'K': printf("Cadeias: %d\n",numCadeiasAD(trie)); break; case 'l': case 'L': liberaAD(trie); break; case 'h': case 'H': printf("# : comentário.\n"); printf("c : cria e devolve uma AD vazia\n"); printf("i s : insere a cadeia s na AD\n"); printf("v s : verifica se a cadeia s está na AD\n"); printf("r s : remove a a cadeia s está da AD\n"); printf("p : visita as cadeias da AD em ordem alfabética\n"); printf("n : imprime o número de nós da AD\n"); printf("a : imprime a altura da AD\n"); printf("k : imprime o número de cadeias da AD\n"); printf("l : libera a memória dinâmica ocupada pela AD\n"); printf("h : imprime resumo.\n"); printf("x : término.\n"); printf("q : término.\n"); break; case 'x': case 'X': case 'q': case 'Q': fim = true; break; default: printf("Acao invalida\n"); break; } /* switch */ } while (!fim); bapply(bprint); printf("Processamento terminado\n"); return 0; } /* main */
// Make a popup dialog box SpinBoard::SpinBoard(MainForm *mainForm, QWidget * parent) : QDialog(parent), mainForm(mainForm) { setWindowTitle( "AViz: Set Spins" ); { // Create a hboxlayout that will fill the first row hb1 = new QWidget(this); // Create a combo box that will go into the // second column; entries in the combo box will // be made later spinCob = new QComboBox(); connect( spinCob, SIGNAL(activated(int)), SLOT(setSpin()) ); // Add a check box button showSpinCb = new QCheckBox("Show Spins"); showSpinCb->setChecked(true); // Define a callback for this toggle switch connect( showSpinCb, SIGNAL(clicked()), this, SLOT(adjustSpin()) ); QHBoxLayout *hbox = new QHBoxLayout(hb1); hbox->addWidget(new QLabel(" Type: ")); hbox->addWidget(spinCob); hbox->addStretch(1); hbox->addWidget(showSpinCb); } { // Create a hboxlayout that will fill the next row hb2 = new QWidget(this); // Add color labels colorLabel0 = new ColorLabel(hb2); colorLabel1 = new ColorLabel(hb2); colorLabel2 = new ColorLabel(hb2); colorLabel3 = new ColorLabel(hb2); colorLabel4 = new ColorLabel(hb2); colorLabel5 = new ColorLabel(hb2); colorLabel0->setFixedHeight( LABEL_HEIGHT ); colorLabel1->setFixedHeight( LABEL_HEIGHT ); colorLabel2->setFixedHeight( LABEL_HEIGHT ); colorLabel3->setFixedHeight( LABEL_HEIGHT ); colorLabel4->setFixedHeight( LABEL_HEIGHT ); colorLabel5->setFixedHeight( LABEL_HEIGHT ); // Add a push button colorButton = new QPushButton("Set Color..."); // Define a callback for this button connect(colorButton, SIGNAL(clicked()), SLOT(setColorCb())); QHBoxLayout *hbox = new QHBoxLayout(hb2); hbox->setSpacing(0); hbox->addWidget(new QLabel(" Color: ")); hbox->addWidget(colorLabel0); hbox->addWidget(colorLabel1); hbox->addWidget(colorLabel2); hbox->addWidget(colorLabel3); hbox->addWidget(colorLabel4); hbox->addWidget(colorLabel5); hbox->addWidget(colorButton); } // Create a hboxlayout that will fill the next row sizeBox = new SizeBox(this); { // Create a hboxlayout that will fill the next row hb4 = new QWidget(this); // Add radiobuttons and a label modeL = new QLabel(" Color Criterion: "); colorMode = new QGroupBox(); QHBoxLayout *colorModeLayout = new QHBoxLayout(colorMode); colorMode0 = new QRadioButton("Type"); colorMode1 = new QRadioButton("Position"); colorMode2 = new QRadioButton("Property"); colorMode3 = new QRadioButton("ColorCode"); colorModeLayout->addWidget(colorMode0); colorModeLayout->addWidget(colorMode1); colorModeLayout->addWidget(colorMode2); colorModeLayout->addWidget(colorMode3); QButtonGroup *colorModeButtonGroup = new QButtonGroup(this); colorModeButtonGroup->addButton(colorMode0); colorModeButtonGroup->addButton(colorMode1); colorModeButtonGroup->addButton(colorMode2); colorModeButtonGroup->addButton(colorMode3); // Define a callback for these radio buttons connect(colorModeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(adjustCriterion()) ); QHBoxLayout *hBox = new QHBoxLayout(hb4); hBox->addWidget(modeL); hBox->addWidget(colorMode); } // Create hboxlayouts that will fill the next row; these // are shown only when appropriate positionBox = new PositionBox(this); propertyBox = new PropertyBox(this); codeBox = new CodeBox(this); // Create a box that will fill the next row lineTypeBox = new LineTypeBox( this ); { hb5 = new DoneApplyCancelWidget(this); connect(hb5, SIGNAL(done()), this, SLOT(bdone()) ); connect(hb5, SIGNAL(applied()), this, SLOT(bapply()) ); connect(hb5, SIGNAL(canceled()), this, SLOT(bcancel())); } // Clear the board pointer spinBox = NULL; // Clear the color board pointer cb = NULL; // Clear internal variables colors = 1; colorPosX = colorPosY = 0; showColorBoard = false; spinRenderStyle = SLINE; renderQuality = LOW; // Set defaults lineTypeBox->setDisabled(true); // Set defaults appropriate for startup without data colorButton->setDisabled(true); sizeBox->setDisabled(true); modeL->setDisabled(true); colorMode->setDisabled(true); colorMode0->setChecked(true); // Build default layout this->buildLayout( TYPE ); }
int main() { Aluno aluno; Base base; Boolean fim = false; int ra; char acao; base = CriaBase(); do { if (scanf("%c", &acao) == EOF) fim = true; else { printf("Ação: %c", acao); switch (acao) { case '#': ImprimeComentario(); break; case 'i': case 'I': scanf("%d ",&aluno.ra); aluno.nome = leNome(); printf(" %06d %s\n", aluno.ra, aluno.nome); if (!InsereBase(&base, aluno)) { printf("Ra %06d já estava presente na base de dados.\n", aluno.ra); FREE(aluno.nome); } break; case 'c': case 'C': scanf("%d",&ra); printf(" %06d",ra); ImprimeComentario(); if (ConsultaBase(&base, ra, &aluno)) printf("%06d %s \n", ra, aluno.nome); else printf("Ra %06d não encontrado na base de dados.\n", ra); break; case 'r': case 'R': scanf("%d",&ra); printf(" %06d",ra); ImprimeComentario(); if (RemoveBase(&base, ra)) printf("Ra %06d removido.\n", ra); else printf("Ra %06d não encontrado na base de dados.\n", ra); break; case 'n': case 'N': ImprimeComentario(); printf("Número de nós na base de dados: %d.\n", NumeroNosBase(&base)); break; case 'a': case 'A': ImprimeComentario(); printf("Altura da base de dados: %d.\n", AlturaBase(&base)); break; case 'l': case 'L': ImprimeComentario(); LiberaBase(&base); base = CriaBase(); break; case 'p': case 'P': ImprimeComentario(); PercorreBase(&base,ImprimeAluno); break; case 'h': case 'H': ImprimeComentario(); printf("\n"); printf("# : comentário.\n"); printf("i <ra> <nome> : insere ra e nome na base.\n"); printf("c <ra> : consulta ra na base.\n"); printf("r <ra> : remove ra da base.\n"); printf("l : libera base.\n"); printf("p : executa um percurso inordem na base.\n"); printf("n : verifica número de nós na base.\n"); printf("a : verifica altura da base.\n"); printf("h : imprime resumo.\n"); printf("x : término.\n"); printf("q : término.\n"); fim = true; break; case 'x': case 'X': case 'q': case 'Q': ImprimeComentario(); fim = true; break; } /* switch */ } } while (!fim); bapply(bprint); printf("Processamento terminado\n"); return 0; } /* main */
int main() { char acao; Polinomio v[4]; int k, m, n; int e; float c; Boolean fim = false; /* --------------------------------------------------------------------------- */ do { scanf("%c", &acao); printf("Ação: %c", acao); switch (acao) { case '#': ImprimeComentario(); break; case 'c': case 'C': scanf("%d",&k); printf("%2d",k); ImprimeComentario(); v[k-1] = CriaPolinomioNulo(); break; case 'l': case 'L': scanf("%d",&k); printf("%2d",k); ImprimeComentario(); LiberaPolinomio(v[k-1]); break; case 'n': case 'N': scanf("%d",&k); printf("%2d",k); ImprimeComentario(); if (PolinomioNulo(v[k-1])) printf("Polinomio %d é nulo\n",k); else printf("Polinomio %d não é nulo\n",k); break; case 't': case 'T': scanf("%d%d%f",&k,&e,&c); printf("%2d%3d%5.1f",k,e,c); ImprimeComentario(); InsereTermo(v[k-1],e,c); break; case 'i': case 'I': scanf("%d",&k); printf("%2d",k); ImprimeComentario(); printf("----> "); ImprimePolinomio(v[k-1]); break; case 's': case 'S': scanf("%d%d%d",&k,&m,&n); printf("%2d%2d%2d",k,m,n); ImprimeComentario(); v[k-1] = SomaPolinomios(v[m-1],v[n-1]); break; case 'r': case 'R': scanf("%d%d%d%f",&k,&m,&e,&c); printf("%2d%2d%3d%5.1f",k,m,e,c); ImprimeComentario(); v[k-1] = MultTermo(v[m-1],e,c); break; case 'm': case 'M': scanf("%d%d%d",&k,&m,&n); printf("%2d%2d%2d",k,m,n); ImprimeComentario(); v[k-1] = MultPolinomios(v[m-1],v[n-1]); break; case 'h': case 'H': ImprimeComentario(); printf("\n"); printf("# : comentário\n"); printf("c k : v[k] := 0\n"); printf("l k : Libera v[k]\n"); printf("n k : testa se v[k]=0\n"); printf("t k e c : acrescenta termo (e,c) a v[k]\n"); printf("i k : imprime v[k]\n"); printf("s k m n : v[k] := v[m]+v[n]\n"); printf("r k m e c : v[k] := v[m]*(e,c)\n"); printf("m k m n : v[k] := v[m]*v[n]\n"); printf("x : término\n"); printf("q : término\n"); printf("h : imprime resumo\n"); fim = true; break; case 'x': case 'X': case 'q': case 'Q': ImprimeComentario(); fim = true; break; } /* switch */ } while (!fim); /* Verifica se foram liberados todos os blocos alocados */ bapply(bprint); printf("Processamento terminado\n"); return 0; } /* main */
int main(int argc, char * argv[]) { /* Os argumentos são os nomes dos dois arquivos que contêm, respectivamente, os dados para inserção e as operacoes. A saída é para o arquivo 'stdout'. */ Aluno a; int ra; char op; Base p; FILE * dados; FILE * operacoes; if (argc!=3) { /* verifica o número de argumentos */ printf("Faltam ou sobram nomes dos arquivos\n"); return 1; } dados = fopen(argv[1],"r"); operacoes = fopen(argv[2],"r"); if ((dados==NULL) || (operacoes==NULL)) { printf("Problmas na abertura dos arquivos\n"); return 1; } buf = MALLOC(ComprMaxNome); p = CriaBase(); printf("Carga inicial dos dados:\n"); while (LeAluno(dados,&a)) { if (!InsereBase(p,&a)) { printf("RA=%d repetido\n",a.ra); FREE(a.nome); } } printf("\nOperações:\n"); while (fscanf(operacoes,"%c",&op)!=EOF) { switch (op) { case 'i': LeAluno(operacoes,&a); /* ignora o resultado booleano */ printf("Insere: %d %s\n",a.ra,a.nome); if (!InsereBase(p,&a)) { printf("RA=%d repetido\n",a.ra); FREE(a.nome); } break; case 'r': fscanf(operacoes,"%d\n",&ra); printf("Remove: %d\n",ra); if (!RemoveBase(p,ra)) printf("RA inexistente: %6d\n",ra); break; case 'c': fscanf(operacoes,"%d\n",&ra); printf("Consulta: %d\n",ra); if (ConsultaBase(p,ra,&a)) printf("%6d %s\n",a.ra, a.nome); else printf("RA inexistente: %6d\n",ra); break; case 'w': fscanf(operacoes,"\n"); printf("\nImprime base: %d registro(s):\n",NumeroRegsBase(p)); ImprimeBase(p); printf("\n"); break; default: fscanf(operacoes,"\n"); printf("Operacao invalida: %c\n",op); break; } } LiberaBase(p); FREE(buf); fclose(dados); fclose(operacoes); bapply(bprint); printf("\nProcessamento terminado\n"); return 0; }
int main() { struct conjunto* C[10]; int i; for( i = 0; i < 10; ++i ) C[i] = criar_conjunto(); //cria os 10 conjuntos vazios //ou: //C[i] = NULL for( i = 0; i < 10; ++i ) inicia_lista(C[i]); conjunto* c; char op; int c1,c2,c3; while( 1 ) { scanf("%c", &op); switch( op ) { case 'A': scanf("%d %d", &c1, &c2); inserir_elemento(C[c1-1],c2); break; case 'R': scanf("%d %d", &c1, &c2); remover_elemento(C[c1-1],c2); break; case 'L': scanf("%d", &c1); listar_elementos(C[c1-1]); break; case 'F': scanf("%d", &c1); deletar_conjunto(C[c1-1]); C[c1-1] = criar_conjunto(); inicia_lista(C[c1-1]); break; case 'I': scanf("%d %d %d", &c1, &c2, &c3); c = intersecao(C[c1-1],C[c2-1]); deletar_conjunto(C[c3-1]); C[c3-1] = c; break; case 'U': scanf("%d %d %d", &c1, &c2, &c3); c = uniao(C[c1-1],C[c2-1]); deletar_conjunto(C[c3-1]); C[c3-1] = c; break; case 'P': scanf("%d %d", &c1, &c2); if(pertinencia(C[c1-1],c2)) printf("S\n"); else printf("N\n"); break; case 'D': scanf("%d %d %d", &c1, &c2, &c3); c = diferenca(C[c1-1],C[c2-1]); deletar_conjunto(C[c3-1]); C[c3-1] = c; break; case 'C': scanf("%d %d", &c1, &c2); if(subconjunto(C[c1-1],C[c2-1])) printf("S\n"); else printf("N\n"); break; case '=': scanf("%d %d", &c1, &c2); if(igualdade(C[c1-1],C[c2-1])) printf("S\n"); else printf("N\n"); break; case '#': scanf("%d", &c1 ); printf("%d\n", cardinalidade( C[c1-1]) ); break; case 'X': for( i = 0; i < 10; ++i ) deletar_conjunto(C[i]); bapply(bprint); //não modifique esta linha return 0; } } }
int main() { char acao; num_matriz k, k1, k2, k3; int m, n, i, j; float x; matriz a[num_nomes]; while (true) { scanf("%c", &acao); printf("ação: %c", acao); switch (acao) { case 'r': le_nome(&k); prox_linha(); printf(" %c\n", min_nome+k); le_matriz(&a[k]); break; case 'z': le_nome(&k); scanf("%d %d", &m, &n); prox_linha(); printf(" %c %d %d\n", min_nome+k, m, n); inicializa(&a[k], m, n); break; case 'v': le_nome(&k); scanf("%d %d", &i, &j); prox_linha(); printf(" %c %d %d\n", min_nome+k, i, j); printf(" %c[%d,%d] = %8.2f\n", min_nome+k, i, j, valor(&(a[k]), i, j)); break; case 'a': le_nome(&k); scanf("%d %d %f", &i, &j, &x); prox_linha(); printf(" %c %2d %2d %8.2f\n", min_nome+k, i, j, x); atribui(&a[k], i, j, x); break; case 's': le_nome(&k1); le_nome(&k2); le_nome(&k3); prox_linha(); printf(" %c %c %c\n", min_nome+k1, min_nome+k2, min_nome+k3); soma(&a[k1], &a[k2], &a[k3]); break; case 'm': le_nome(&k1); le_nome(&k2); le_nome(&k3); prox_linha(); printf(" %c %c %c\n", min_nome+k1, min_nome+k2, min_nome+k3); multiplica(&a[k1], &a[k2], &a[k3]); break; case 't': le_nome(&k1); le_nome(&k2); prox_linha(); printf(" %c %c\n", min_nome+k1, min_nome+k2); transpoe(&a[k1], &a[k2]); break; case 'w': le_nome(&k); prox_linha(); printf(" %c\n", min_nome+k); imprime_matriz(&a[k]); break; case 'x': printf("\n"); bapply(bprint); printf("fim da execução.\n"); exit(0); break; case '#': { int c; do { c = getchar(); putchar(c); } while ((c != '\n') && (c != EOF)); } break; case 'l': le_nome(&k); prox_linha(); printf(" %c\n", min_nome+k); libera(&a[k]); break; default: { erro("ação inválida"); } } /* switch */ } /* while */ bapply(bprint); return 0; } /* main */