how do I identify the amount that was repeated and the names repeated?
Make an algorithm in portugol that reads the name of up to 100 people and reports the amount of names equal to "jose da silva" and the amount 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
0
1 answers
A tip to help you: break the problem into parts to facilitate your implementation:
-
You should read until 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 by 1 and and
- If the counter reaches 100 you exit the loop
-
You must have a counter for each of the names that will search the repeat:
- each time a non-empty name is read
- If the name is equal to " José da Silva", increase his counter by 1 and
- if the name is equal to "Ana Maria" you increment her counter by 1.
-
You must write the number of repetitions.
- this will only run after all 100 names have been read
- then you write the name counter value of the " Jose da Silva ' and
- writes the name counter value of " Ana Maria ".
Implement each part in order and you will see the resolution has become much simpler.
0
Author: Giovanni Nunes, 2018-03-25 21:37:36