Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
otro avance de pregunta 2
#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("%s\n", 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 ); } /* -------------------------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 (ptrPivot -> cantidad) - (ptrElement -> cantidad); } void lowerCase( char *domain) { while ( *domain != '\0') { if ( isupper( *domain ) ) *domain = tolower(*domain); domain ++; } }
run
|
edit
|
history
|
help
0
array and its sum
Vereinfachung
light blue zoda
linear hybrid cellular automaton utilizing rules 90 and 150 with period of (2^64)-1 for generating high quality random bits is reversible
20171117_FUNCIONES
Factorial Descompuesto en Potencias de Numeros Primos
C141105_SwitchNotas
demo_strlen
2.1 Comparision of Matrix Transpose Execution Time
Print hostname