ponto *soma(ponto* G, bigint n,bigint a) { bigint i; if(n==1) return G; ponto *R_temp=dobro_ponto(G,a), *G_temp=G; for(i=2;i<n;i++){ //printf("i:%lld G(%lld,%lld) R(%lld,%lld)\n",i,G->x,G->y,R_temp->x,R_temp->y); int opcao = igualdade(G,R_temp); switch(opcao){ case NEGATIVO: R_temp->x = 0; R_temp->y = 0; break; case FALSO: R_temp = soma_pontos(G,R_temp); break; case VERDADE: R_temp = dobro_ponto(G,a); break; case P1_MAIS_INFINITO: R_temp->x = G->x; R_temp->y = G->y; break; } } return R_temp; }
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; } } }