TOPIC

35% Código Simples

@pl_starlord asked 6 months ago

Simplifiquei bastante, agora serve pra maiúsculo e minúsculo mas não passa em C (meu algoritmo).

I simplified it a lot, now it's for upper and lower case but it doesn't pass in C (my algorithm).

#include <stdio.h>
#include <string.h>

int main() 
{   
    int n, m;
    int i;
    int tam; 
    char e, s;
    char frase[10010];
    char trocas[256];
    int foiTrocado[256];

    for (i = 0; i < 256; i++) foiTrocado[i] = 0;

    scanf ("%d %d", &n, &m);

    for (i = 0; i < n; i++)
    {   
        getchar();
        scanf ("%c %c", &e, &s);

        trocas[(int) e] = s;
        trocas[(int) s] = e;

        foiTrocado[(int) e] = 1;
        foiTrocado[(int) s] = 1;
    }

    while (m--)
    {   
        getchar();
        scanf ("%[^\n]s", frase);
        tam = strlen(frase);

        for (i = 0; i < tam; i++)
        {  
            if (foiTrocado[(int) frase[i]] == 1)
            {
                printf ("%c", trocas[(int) frase[i]]);
            }
            else
            {
                printf ("%c", frase[i]);
            }
        }
        printf("\n");
    }

    return 0;
}
MOD

Remember not post solutions. Your post may be reviewed by our moderators.

  • Diego Rangel replied 5 months ago

    Pode ter letras maiúsculas trate isso.

  • @pl_starlord replied 5 months ago

    I changed and unfortunately it didn't work, but thank you very much

    MOD
  • feodorv replied 6 months ago

                while (teste && (k++ < n * 2))

    Seems you mean

                while (teste && (++k < n * 2))