Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<stdio.h>
- #include<stdlib.h>
- using namespace std;
- /*
- copiar:
- 1
- ola
- 3
- 4
- 3
- 4
- 2
- ole
- 5
- 6
- 5
- 6
- 0
- */
- typedef struct eq{
- char nome[40];
- int vit,der,set_g,set_p;
- struct eq *link;
- } equipa;
- equipa *inicio=NULL, *temp=NULL,*ant=NULL,*aux=NULL;
- FILE *fx;
- struct fich{
- char nome[40];
- int vit,der,set_g,set_p;
- } expe;
- void inserir(){
- //temp=inicio;
- system("cls");
- cout << "EX 1\n\nPrima 0 para parar\n";
- int n=1;
- char s[40];
- while(n!=0){
- temp=(equipa*) malloc(sizeof(equipa));
- cout << "Nome: "; cin >> s;
- //verificar nome
- if(inicio!=NULL){
- aux=inicio;
- while(strcmp(aux->nome,s) and aux->link!=NULL){
- aux=aux->link;
- }
- //cout << "depois";
- if(!strcmp(aux->nome,s)){
- //cout << "Encontramos o nome " << temp->nome << ", com o numero " << temp->numero << endl;
- //strcpy(temp->nome,str);
- cout << "Por favor repita o processo\n";
- continue;
- }
- }
- strcpy(temp->nome,s);
- cout << "Vit: "; cin >> temp->vit;
- cout << "Derrotas:"; cin >> temp->der;
- cout << "SET G: "; cin >> temp->set_g;
- cout << "SET P: "; cin >> temp->set_p;
- if(inicio==NULL){
- inicio = temp;
- inicio->link=NULL;
- }
- //se for < inserir antes se nao continuo a verificar a lista
- else{
- if(temp->vit<=inicio->vit){
- temp->link=inicio;
- inicio=temp;
- }
- else{
- ant=inicio;
- aux=inicio;
- while(aux->vit<temp->vit && aux->link!=NULL){
- ant=aux;
- aux=aux->link;
- }
- if(aux->vit>temp->vit){
- ant->link=temp;
- temp->link=aux;
- }
- else if(aux->vit<temp->vit){
- temp->link=aux->link;
- aux->link=temp;
- }
- //se forem iguais, dividir pelos set's ganhos
- else{
- if((aux->set_g - aux->set_p)<(temp->set_g - aux->set_p)){
- ant->link=temp;
- temp->link=aux;
- }
- else{
- temp->link=aux->link;
- aux->link=temp;
- }
- }
- }
- }
- cout << "Continuar? "; cin >> n;
- }
- }
- void listar(){
- system("cls");
- cout << "LISTAGEM CARALHOOO\n";
- //cout << "Esta vazia :(\n";
- temp=inicio;
- if(inicio!=NULL){
- while(temp!=NULL){
- cout<<"Nome: "<<temp->nome<<"\nVit: "<< temp->vit<<"\nDerr: "<< temp->der<<"\nSet G: "<<temp->set_g<<"\nSet P: "<<temp->set_p<<"____"<<endl;
- temp=temp->link;
- }
- }
- else cout << "Esta vazia\n";
- }
- void eliminar(){
- system("cls");
- cout << "ELIMINAR CENA";
- cout << "Insira o numero a pesquisar: ";
- int n; cin >> n;
- temp=inicio;
- if(inicio!=NULL){
- if((inicio->vit + inicio->der)==n){
- cout << "Eliminada a equipa: " << inicio->nome << endl;
- inicio=inicio->link;
- }
- else{
- while((temp->vit + temp->der)!=n and temp->link!=NULL){
- //cout << "Numero: " << temp->numero << " e o Nome: " << (*temp).nome << endl;
- //cout << "ola" << endl;
- aux=temp;
- temp=temp->link;
- }
- if((temp->vit + temp->der) == n){
- cout << "Eliminada a equipa: " << temp->nome << endl;
- //temp=temp->link;
- aux->link=temp->link;
- }
- else cout << "Nao encontrado\n";
- }
- }
- else cout << "Esta vazia\n";
- }
- //1- ver quantos há - x
- //2- os melhores vão ser os das posições (x-n) até ao fim
- void exportar(){
- system("cls");
- cout << "expeORTAR\n";
- cout << "Quantos classificados quer? ";
- int n,q=0; cin >> n;
- temp=inicio;
- if(inicio!=NULL){
- while(temp!=NULL){
- q++;
- temp=temp->link;
- }
- }
- temp=inicio;
- int i = 0;
- while((q-n)!=i){
- temp=temp->link;
- i++;
- }
- while(temp!=NULL){
- if(!(fx=fopen("dados.dat","a"))) cout << ("Erro 404\n");
- else{
- expe.vit=temp->vit;
- expe.der=temp->der;
- expe.set_g=temp->set_g;
- expe.set_p=temp->set_p;
- strcpy(expe.nome,temp->nome);
- fwrite(&expe,sizeof(expe),1,fx);
- fclose(fx);
- }
- temp=temp->link;
- }
- }
- void ler(){
- system("cls");
- cout << "LER O CARALHO DO FICHEIRO\n";
- fx=fopen("dados.dat", "r");
- fread(&expe, sizeof(expe), 1, fx);
- while(!feof(fx)){
- cout<<"\nNome: "<<expe.nome<<"\nVit: "<<expe.vit<<"\nDer: "<<expe.der<<"\nSet G: "<<expe.set_g<<"\nSet P: "<<expe.set_p<<"\n_____\n";
- fread(&expe, sizeof(expe),1, fx);
- }
- fclose(fx);
- }
- void asneiras(){
- temp=inicio;
- if(inicio!=NULL){
- if(!(inicio->set_g)){
- inicio=inicio->link;
- }
- else{
- while(!(temp->set_g) and temp->link!=NULL){
- aux=temp;
- temp=temp->link;
- }
- if(!(temp->set_g)){
- aux->link=temp->link;
- }
- }
- }
- }
- void set0(){
- system("cls");
- cout << "ELIMINAR SET 0\n";
- temp=inicio;
- if(inicio!=NULL){
- if(!(inicio->set_g)){
- //cout << "Eliminada a equipa: " << inicio->nome << endl;
- inicio=inicio->link;
- cout << "Eliminado com sucesso!\n";
- }
- else{
- while(!(temp->set_g) and temp->link!=NULL){
- //cout << "Numero: " << temp->numero << " e o Nome: " << (*temp).nome << endl;
- //cout << "ola" << endl;
- aux=temp;
- temp=temp->link;
- }
- if(!(temp->set_g)){
- //cout << "Eliminada a equipa: " << temp->nome << endl;
- //temp=temp->link;
- aux->link=temp->link;
- cout << "Eliminado com sucesso!\n";
- }
- else cout << "Nao encontrado\n";
- }
- }
- else cout << "Esta vazia\n";
- for(int i=0;i<20;i++) asneiras();
- }
- int main(){
- string s;
- while(true){
- cout << "\n1. Inserir Equipas\n2. Listar\n3. Eliminar\n4. expeortar\n5. Ler Ficheiro\n6. Eliminar Set0\n->";
- cin >> s;
- if(s=="0") break;
- else if(s=="1") inserir();
- else if(s=="2") listar();
- else if(s=="3") eliminar();
- else if(s=="4") exportar();
- else if(s=="5") ler();
- else if(s=="6") set0();
- else {
- system("cls");
- cout << "errozinho\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment