Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Check Input
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; class Rextester { // get number before "(" like 123( ... 2( ... 3( ... 12( public static int getnum(String s,int i) { int index = i-1; while (index >= 0 && Character.isDigit(s.charAt(index))) index--; return (i - index - 1); } public static void main(String args[]) { String s ="2(245(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)2(2(hi)2(co))x2(bo)"; int first,second =0; while(true) { first = second = -1; for (int i=0; i< s.length(); i++) { if (s.charAt(i) == '(') first = i; if (s.charAt(i) == ')') { second = i; break; } } if (second != -1 && first != -1) { int num = 0; String s1; int total_num = getnum(s,first); total_num = first - total_num; for (int i = total_num; i < first; i++) num = num * 10 + Character.getNumericValue(s.charAt(i)); s1 = s.substring(0,total_num); for (int i=1; i<= num; i++) s1 += s.substring(first + 1,second); s = s1 + s.substring(second + 1, s.length()); } else break; } System.out.println(s); } }
run
|
edit
|
history
|
help
0
predecrement
Fibonacci numbers 0 - 94
Union of Arrays
massive
Brackets balancing
1 to 100 except 30 to40
클래스의 정의와 인스턴스 생성
Display Page
Problem: rstring
Java