Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
experimento con quicksort
#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> typedef struct { char mail[321]; char domain[256]; }users; typedef struct { char dominio[256]; unsigned short cantidad; }domains; // -----------------Prototypes---------------------- void findDomain ( char *, char * ); int compareDomains( const void *, const void * ); void lowerCase( char * ); void registroDominio( const users *, domains *, int ); int compareFrequency( const void *, const void* ); // ---------------Main Program----------------------- int main(void) { users typeDomain[10000]; domains arrayDominios[10000]; int i = 0; int total; // --------------------------Input---------------------- while ( i < 10000) { scanf("%320s", typeDomain[i].mail); if ( strcmp(typeDomain[i].mail, "FIN") == 0) break; i++; } // -----------------------Process----------------------- total = i; for (i = 0 ; i < total ; i++) findDomain(typeDomain[i].mail, typeDomain[i].domain); for (i = 0 ; i < total ; i++) lowerCase(typeDomain[i].domain); qsort(typeDomain, total, sizeof(users), compareDomains); for (i = 0 ; i < total ; i++) printf("mail: %s y dominio: %s\n", typeDomain[i].mail , typeDomain[i].domain); printf("\n\n"); registroDominio( typeDomain, arrayDominios, total); return 0; } void registroDominio( const users *type, domains *array, int total) { short i, j = 0; unsigned short suma = 1; int cant = 0; for (i = 0 ; i < total ; i++) { if ( strcmp( type[i].domain, type[i + 1].domain) == 0) suma ++; else { strcpy(array[j].dominio, type[i].domain); array[j].cantidad = suma; suma = 1; cant ++; j ++; } } total = cant; /* for (i = 0 ; i < total ; i++) printf("%s : %hu\n", array[i].dominio, array[i].cantidad );*/ qsort(array, total, sizeof(domains), compareFrequency); printf("\n\n"); for (i = 0 ; i < total ; i++) printf("%s : %hu\n", array[i].dominio, array[i].cantidad ); } /* -------------------------Procedimiento findDomain------------------------------- * Propósito: encontrar el dominio de un correo electrónico. Ejemplo: * pedro@hotmail.com, el dominio es: hotmail.com * */ void findDomain ( char *mail, char *domain) { char *pointer; pointer = mail; pointer = strchr(mail, '@'); strcpy(domain, pointer + 1); } int compareDomains( const void *pivot, const void *element ) { users *ptrPivot = (users *) pivot; users *ptrElement = (users *) element; return strcmp( ( ptrPivot -> domain ), ( ptrElement -> domain ) ); } int compareFrequency( const void *pivot, const void *element ) { domains *ptrPivot = (domains *) pivot; domains *ptrElement = (domains *) element; return (ptrElement -> cantidad) - (ptrPivot -> cantidad); } void lowerCase( char *domain) { while ( *domain != '\0') { if ( isupper( *domain ) ) *domain = tolower(*domain); domain ++; } }
run
|
edit
|
history
|
help
0
1/23/2017
Ad
cstructCensus
fork
18BCE2182 ASSESS_1 Q1-2
Pointer
Bitex
printint a struct
SIGABRT error
ARREGLO DE VARIABLES DE TIPO STRUCT