Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.1 kB
1
Indexable
Never
///Liberías*******************************************************************************************************************************
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <string.h>

///Constantes*****************************************************************************************************************************
# define MAX_CHAR 50
# define MAX_PERS 10

///Estructuras****************************************************************************************************************************
typedef struct {
    char name_M[MAX_CHAR];
    char genderM;
    int ageM;

}Moons;


typedef struct {
    char name_DS[MAX_CHAR];
    char genderDS;
    int ageDS;

}DemonSlayers;



typedef struct {
    DemonSlayers demonslayers[MAX_PERS];
    Moons moons[MAX_PERS];
    int demons;
    int humans;
}Kimetsu_Characters;

///Funciones******************************************************************************************************************************
// D|daki|D|muzan|D|akaza|H|tanjiro|H|mitsuri|H|zenitsu|D|nezuko

///MAIN___________________________________________________________________________________________________________________________________
int main(){
    Kimetsu_Characters personaje;

    char input[100];
    int lenght = 0;
    int i = 0, j = 0;
    int count_demons = 0, count_humans = 0;
    int flag = 0;
    int count = 0;

    printf ("Input: ");
    fgets (input, 100, stdin);
    input [ strlen( input ) - 1 ] = '\0';

    lenght = strlen (input);

    printf ("Your INPUT is: %s", input);
    printf ("\nYour INPUT has %d characters.", lenght);

    while ( input[i] != '\0' ) {
            
//Contar el tipo de personaje
        if ( input[i] == 'D') {
               count_demons++;
               flag = 1;
               i++;
        }
        else if ( input[i] == 'H') {
                count_humans++;
                flag = 2;
                i++;
        }
       
       
        else if ( input[i] >= 'a' && input[i] <= 'z' && flag == 1 ) {
            personaje.moons[count_demons].name_M[j] = input[i];
            j++;
            i++;
        }
        personaje.moons[count_demons].name_M[j + 1] = '\0';

        if ( input[i] >= 'a' && input[i] <= 'z' && flag == 2 ) {
            personaje.demonslayers[count_humans].name_DS[j] = input[i];
            j++;
            i++;
        }
        personaje.moons[count_demons].name_M[1] = '\0';
        personaje.demonslayers[count_humans].name_DS[j + 1] = '\0';

        

    }
    personaje.demons = count_demons;
    personaje.humans = count_humans;

    printf ( "\nTotal of Demons: %d", personaje.demons);
    for ( i = 1; i <= personaje.demons; i++){
    printf ( "\n\t DEMON %i: %s", i, personaje.moons[i].name_M);
    }
    printf ( "\nTotal of Humans: %d", personaje.humans);
    for ( i = 1; i <= personaje.humans; i++){
    printf ( "\n\t HUMAN %i: %s", i, personaje.demonslayers[i].name_DS);
    }

return 0;

}