Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Author: Leandro Soares
- School: INETE
- Date: 24-04-2012
- Time: 15:10 */
- /* IMCOMPLETO DEVIDO AO BARULHO NA AULA */
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct tagGolos {
- char player[122];
- int golos;
- struct tagGolos *pnext;
- struct tagGolos *pprev;
- };
- void Linha_to_Struct(struct tagGolos **pHead, char buffer[]);
- void InsertNode(struct tagGolos **phead, struct tagGolos *pnew);
- struct tagGolos *NewNode(void);
- int isAlphaSpec(char Char);
- void CountGoals(struct tagGolos **pHead, struct tagGolos **pHeadSec);
- int ProcGoalperPlayer(struct tagGolos *pAux, char *Player);
- void ApagarPlayer(struct tagGolos *pStruct);
- int main() {
- FILE * pInput;
- char buffer[121];
- struct tagGolos *pHead, *pHeadSec;
- pHead = NULL;
- pInput = fopen("input.txt", "r");
- while( fgets(buffer, 120, pInput) != NULL ) {
- Linha_to_Struct(&pHead, buffer);
- }
- CountGoals(&pHead, &pHeadSec);
- fclose(pInput);
- return 0;
- }
- void Linha_to_Struct(struct tagGolos **pHead, char buffer[]) {
- int idx;
- char NameAux[120];
- struct tagGolos *pnew;
- pnew = NewNode();
- for(idx=0; isAlphaSpec(buffer[idx]) != 0 ; idx++) {
- NameAux[idx] = buffer[idx];
- }
- NameAux[idx-1] = '\0';
- strcpy(pnew->player, NameAux);
- InsertNode(&(*pHead), pnew);
- }
- int isAlphaSpec(char Char) {
- if ( ( Char >= 'A' && Char <= 'Z' ) || ( Char >= 'a' && Char <= 'z' ) || Char == ' ' )
- return Char;
- return 0;
- }
- void InsertNode(struct tagGolos **phead, struct tagGolos *pnew) {
- struct tagGolos *paux;
- paux = (*phead);
- if( (*phead) != NULL ) {
- (*phead)->pprev = pnew;
- pnew->pnext = (*phead);
- }
- (*phead) = pnew;
- }
- struct tagGolos *NewNode(void) {
- struct tagGolos *Dados;
- Dados = (struct tagGolos*) malloc(sizeof(struct tagGolos));
- Dados->pnext = NULL;
- Dados->pprev = NULL;
- return Dados;
- }
- void CountGoals(struct tagGolos **pHead, struct tagGolos **pHeadSec) {
- struct tagGolos *pnew, *pAux, **pAux2;
- int goals;
- pAux = (*pHead);
- while( pAux != NULL ) {
- pnew = NewNode();
- pAux2 = pAux;
- pnew->golos = ProcGoalperPlayer(&pAux2, pAux->player);
- strcpy(pnew->player, pAux->player);
- pAux = pAux->pnext;
- }
- }
- int ProcGoalperPlayer(struct tagGolos **pAux, char *Player) {
- int goals;
- struct tagGolos *pAux2;
- goals = 0;
- while( (*pAux) != NULL ) {
- if( !strcmp(Player, (*pAux)->player) ) {
- goals++;
- pAux2 = pAux;
- ApagarPlayer(pAux);
- }
- pAux = pAux2;
- (*pAux) = (*pAux)->pnext;
- }
- }
- void ApagarPlayer(struct tagGolos **pStruct) {
- struct tagGolos *pAux;
- pAux = (*pStruct)->pnext;
- (*pStruct)->pprev = NULL;
- (*pStruct)->pnext = (*pStruct)->pnext;
- pStruct = pAux;
- free(*pStruct);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement