/* 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
{
{
String s
= "Hoje em dia, é necessário ser esperto. O nosso dia a dia é complicado. Zé. diafragma. Dia. É. Dia." ; System .
out .
println ( marcarRepetidas
( s, prefixo, sufixo
) ) ; }
Set< String> palavras = new HashSet< String> ( ) ;
Set< String> palavrasRepetidas = new HashSet< String> ( ) ;
for ( String palavra
: s.
split ( "[^a-zA-Zà-úÀ-Ú]+" ) ) { palavra = palavra.toLowerCase ( ) ;
if ( palavra.length ( ) > 0 && palavras.contains ( palavra) )
palavrasRepetidas.add ( palavra) ;
palavras.add ( palavra) ;
}
for ( String palavra
: palavrasRepetidas
) s = s.replaceAll ( "(?<![a-zA-Zà-úÀ-Ú])(?iu)(" + palavra + ")(?![a-zA-Zà-úÀ-Ú])" ,
prefixo + "$1" + sufixo) ;
return s;
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCVN0cmluZyBzID0gIkhvamUgZW0gZGlhLCDDqSBuZWNlc3PDoXJpbyBzZXIgZXNwZXJ0by4gTyBub3NzbyBkaWEgYSBkaWEgw6kgY29tcGxpY2Fkby4gWsOpLiBkaWFmcmFnbWEuIERpYS4gw4kuIERpYS4iOwoJCVN0cmluZyBwcmVmaXhvID0gIjxiPiI7CgkJU3RyaW5nIHN1Zml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