/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Ideone ide = new Ideone();
List<String> palavrasRepetidas = ide.pegaRepetidas(texto);
String saida
= texto.
toString().
replace(palavrasRepetidas.
get(0),
"<b>"+palavrasRepetidas.
get(0)+"</b>");
for (int i=1; i < palavrasRepetidas.size(); i++) {
saida = saida.replace(palavrasRepetidas.get(i), "<b>"+palavrasRepetidas.get(i)+"</b>");
}
}
String textoFormatado
= texto.
toString().
replaceAll("[,.!]",
"");
List<String> palavrasRepetidas = new ArrayList<>();
while (st.hasMoreTokens()) {
String palavra
= st.
nextToken(); if (contaPalavra(palavra, textoFormatado) > 1) {
//System.out.println(palavra + " tem mais de uma vez");
if ( !palavrasRepetidas.contains(palavra) ) {
palavrasRepetidas.add(palavra);
}
}
}
return palavrasRepetidas;
}
private static int contaPalavra
(String palavra,
String texto
) { int count = 0;
while (st.hasMoreTokens()) {
if (st.nextToken().compareTo(palavra) == 0) {
count++;
}
}
return count;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCUlkZW9uZSBpZGUgPSBuZXcgSWRlb25lKCk7CgkJU3RyaW5nQnVmZmVyIHRleHRvID0gbmV3IFN0cmluZ0J1ZmZlcigiSG9qZSBlbSBkaWEsIMOpIG5lY2Vzc8OhcmlvIHNlciBlc3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gKGNvbnRhUGFsYXZyYShwYWxhdnJhLCB0ZXh0b0Zvcm1hdGFkbykgPiAxKSB7CiAgICAgICAgICAgICAgICAvL1N5c3RlbS5vdXQucHJpbnRsbihwYWxhdnJhICsgIiB0ZW0gbWFpcyBkZSB1bWEgdmV6Iik7CiAgICAgICAgICAgICAgICBpZiAoICFwYWxhdnJhc1JlcGV0aWRhcy5jb250YWlucyhwYWxhdnJhKSApIHsKICAgICAgICAgICAgICAgICAgICBwYWxhdnJhc1JlcGV0aWRhcy5hZGQocGFsYXZyYSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgcmV0dXJuIHBhbGF2cmFzUmVwZXRpZGFzOwogICAgfQogICAgCiAgICBwcml2YXRlIHN0YXRpYyBpbnQgY29udGFQYWxhdnJhKFN0cmluZyBwYWxhdnJhLCBTdHJpbmcgdGV4dG8pIHsKICAgICAgICBTdHJpbmdUb2tlbml6ZXIgc3QgPSBuZXcgU3RyaW5nVG9rZW5pemVyKHRleHRvKTsKICAgICAgICBpbnQgY291bnQgPSAwOwogICAgICAgIHdoaWxlIChzdC5oYXNNb3JlVG9rZW5zKCkpIHsKICAgICAgICAgICAgaWYgKHN0Lm5leHRUb2tlbigpLmNvbXBhcmVUbyhwYWxhdnJhKSA9PSAwKSB7CiAgICAgICAgICAgICAgICBjb3VudCsrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHJldHVybiBjb3VudDsKICAgIH0KfQ==