How do I identify the amount that was repeated and the names repeated?

Asked

Viewed 207 times

0

Make an algorithm in Portuguese that reads the name of up to 100 people and enter the number of names equal to "Jose da silva" and the number of names equal to "ana maria". The algorithm should not accept empty names.

algoritmo semNome;
// Síntese
//  Objetivo: ler o nome de até 100 pessoas e informar a quantidade de nomes iguais
//  Entrada :nome
//  Saída   :nomes iguais
//Dados de entada
//joão
//joão
//luca
//Dados de saida
//joão
//1

principal
    // Declarações
    inteiro qtdNomes ;
    texto nome,nomeRepetido;


    // Instruções
    nomeRepetido="nome";
    qtdNomes=0;
    enquanto(qtdNomes<3)faca
        escreval("nome:");
        leia(nome);
        qtdNomes=qtdNomes+1;
    fimEnquanto


    se(comparaTexto(nome,nome)==0)entao
        nomeRepetido=nome;
    fimSe

    se (comparaTexto(nome,nomeRepetido)==0)entao
        escreval("nome:",nome);

    fimSe
fimPrincipal
  • Your code is missing, buddy. Stackoverflow does not distribute code, just fix or revise

  • to Imm, vlw. It’s just that I’m new here .

1 answer

0


A tip to help you: divide the problem into parts to facilitate your implementation:

  1. You should read up 100 valid names (not empty)

    • This is a loop that will repeat until it reaches a condition;
    • If the name is not empty you increment the valid name counter to 1 and e
    • If the counter reaches 100 you get out of the loop
  2. You must have a counter for each of the names that will search the repetition:

    • Each time a non-empty name is read
    • If the name equals "José da Silva", increment his counter by 1 and
    • If the name equals "Ana Maria" you increase her counter by 1.
  3. You must write the number of repetitions.

    • This will only be executed after all 100 names were read
    • Then you write the value of the "José da Silva" and
    • Write the value of the name counter of the "Ana Maria".

Implement each part in order and you will see the resolution is much simpler.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.