Home > Back-end >  String String aaabbbccef finally output a3b3c2ef conditions: ababab without output
String String aaabbbccef finally output a3b3c2ef conditions: ababab without output

Time:10-06

Bosses look: String String aaabbbccef finally output a3b3c2ef conditions: ababab without output

CodePudding user response:

The compression of the string, online search a lot of

CodePudding user response:

Don't ababab output? This condition is bizarre

CodePudding user response:

Use regular expressions to match,

CodePudding user response:

Import the Java. Util. *;
Class a {
Public static void main (String [] args) {
String STR="aaabbbccef";
Map Maps=new HashMap (a);
for(int i=0; iThe String key=String. The valueOf ((STR) charAt (I)));
if(! Maps. Either containsKey (key))
Maps. The put (key, 1);
The else {
Int val=maps. Get (key);
Maps. The put (key, val + 1);
}
}
String tem="";
For (Map) Entry I: maps. EntrySet ()) {
If ((int) i.g etValue ()==1) {
Tem +=i.g etKey ();
} else {
Tem +=i.g etKey () + "" + i.g etValue ();
}
}
System. The out. Println (tem);
}
}
  • Related