Skip to content

Instantly share code, notes, and snippets.

@takashima0411
Created March 1, 2015 06:20
Show Gist options
  • Save takashima0411/2754569066019dc544a4 to your computer and use it in GitHub Desktop.
Save takashima0411/2754569066019dc544a4 to your computer and use it in GitHub Desktop.
高橋くんと文字列圧縮(http://abc019.contest.atcoder.jp/tasks/abc019_2)
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
private static final Pattern pattern = Pattern.compile("([a-z])\\1*");
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String org = sc.next();
Matcher matcher = pattern.matcher(org);
while(matcher.find()){
String matched = matcher.group();
System.out.print(matched.charAt(0) + "" + matched.length());
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment