-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncode.java
More file actions
35 lines (35 loc) · 745 Bytes
/
Encode.java
File metadata and controls
35 lines (35 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
class Encode
{
static int i;
static String f(String s)
{
StringBuilder r=new StringBuilder();
while(i<s.length())
{
char c=s.charAt(i++);
if(Character.isDigit(c))
{
int k=c-'0';
while(i<s.length()&&Character.isDigit(s.charAt(i)))
k=k*10+s.charAt(i++)-'0';
i++;
String t=f(s);
while(k-- >0)
r.append(t);
}
else if(c==']')
return r.toString();
else
r.append(c);
}
return r.toString();
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String s=in.nextLine();
i=0;
System.out.println("Output:"+f(s));
}
}