/* package whatever; // don't place package name! */
import java.util.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
// Definimos la vqariable retornada y una estructura de datos (hash table)
// que contendra el caracter y las veces que será borrado de la cadena
StringBuilder result = null;
// Bucle que recorre la cadena y va añadiendo las letras y sumando (borrando) las
// coincidencias
for ( int i = 0; i < str.length(); i++ ) {
if ( what.containsKey ( str.charAt ( i ) ) ) {
what.put ( str.charAt ( i ), what.remove ( str.charAt ( i ) ) + 1 );
} else {
what.put ( str.charAt ( i ), 1 );
}
}
Iterator
<Map.
Entry<Character, Integer
>> it
= freq.
iterator();
// Mostramos el resultado en la pantalla
while ( it.hasNext() ) {
result.append(str);
System.
out.
println(item.
getValue()); }
return result.toString();
}
{
Ideone.
Remove("this is a string",
new HashMap
<Character, Integer
>() { {'t',
1 },
{'i',
2 }}); // --> "hs s a string" Ideone.
Remove("hello world",
new HashMap
<Character, Integer
>() { { 'x',
5 },
{'i',
2 }}); // --> "hello world" Ideone.
Remove("apples and bananas",
new HashMap
<Character, Integer
>() { {'a',
50 },
{'n',
1 }}); // --> "pples d bnns" }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwoKLyogTmFtZSBvZiB0aGUgY2xhc3MgaGFzIHRvIGJlICJNYWluIiBvbmx5IGlmIHRoZSBjbGFzcyBpcyBwdWJsaWMuICovCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIFN0cmluZyBSZW1vdmUoU3RyaW5nIHN0ciwgTWFwPENoYXJhY3RlciAsIEludGVnZXI+IHdoYXQpewoKICAgICAgICAvLyBEZWZpbmltb3MgbGEgdnFhcmlhYmxlIHJldG9ybmFkYSB5IHVuYSBlc3RydWN0dXJhIGRlIGRhdG9zIChoYXNoIHRhYmxlKQogICAgICAgIC8vIHF1ZSBjb250ZW5kcmEgZWwgY2FyYWN0ZXIgeSBsYXMgdmV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W5kKHN0cik7CgogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oaXRlbS5nZXRWYWx1ZSgpKTsKICAgICAgICB9CgogICAgICAgIHJldHVybiByZXN1bHQudG9TdHJpbmcoKTsKICAgIH0KCQoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJSWRlb25lLlJlbW92ZSgidGhpcyBpcyBhIHN0cmluZyIsIG5ldyBIYXNoTWFwPENoYXJhY3RlciwgSW50ZWdlcj4oKSB7IHsndCcsIDEgfSwgeydpJywgMiB9fSk7IC8vIC0tPiAiaHMgcyBhIHN0cmluZyIKCQlJZGVvbmUuUmVtb3ZlKCJoZWxsbyB3b3JsZCIsIG5ldyBIYXNoTWFwPENoYXJhY3RlciwgSW50ZWdlcj4oKSB7IHsgJ3gnLDUgfSwgeydpJywyIH19KTsgLy8gLS0+ICJoZWxsbyB3b3JsZCIKCQlJZGVvbmUuUmVtb3ZlKCJhcHBsZXMgYW5kIGJhbmFuYXMiLCBuZXcgSGFzaE1hcDxDaGFyYWN0ZXIsIEludGVnZXI+KCkgeyB7J2EnLCA1MCB9LCB7J24nLCAxIH19KTsgLy8gLS0+ICJwcGxlcyBkIGJubnMiCgl9Cn0=
Main.java:42: error: not a statement
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: ';' expected
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: illegal start of type
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: ';' expected
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: illegal start of type
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: <identifier> expected
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: ';' expected
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: ')' expected
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:42: error: illegal start of expression
Ideone.Remove("this is a string", new HashMap<Character, Integer>() { {'t', 1 }, {'i', 2 }}); // --> "hs s a string"
^
Main.java:43: error: not a statement
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: ';' expected
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: illegal start of type
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: ';' expected
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: illegal start of type
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: <identifier> expected
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: ';' expected
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: ')' expected
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:43: error: illegal start of expression
Ideone.Remove("hello world", new HashMap<Character, Integer>() { { 'x',5 }, {'i',2 }}); // --> "hello world"
^
Main.java:44: error: not a statement
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: ';' expected
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: illegal start of type
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: ';' expected
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: illegal start of type
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: <identifier> expected
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: ';' expected
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: ')' expected
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
Main.java:44: error: illegal start of expression
Ideone.Remove("apples and bananas", new HashMap<Character, Integer>() { {'a', 50 }, {'n', 1 }}); // --> "pples d bnns"
^
27 errors