
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
sc.close();
while(str.contains("]")) {
int right = str.indexOf("]");
int left = str.lastIndexOf("[",right);
String s = str.substring(left+1,right);
String[] p = s.split("\\|");
str = str.replace("[" + s + "]",String.join("",Collections.nCopies(Integer.parseInt(p[0]),p[1])));
}
System.out.println(str);
}
}
这篇文章展示了如何使用Java的Scanner类从输入的字符串中,根据找到的[和]定位子串,并用数组中的值进行替换操作。
669





