import
java.io.*;
import
java.util.*;
class
GFG
{
static
void
GetAllValidIpAddress(ArrayList<String>result,
String givenString,
int
index,
int
count, String ipAddress){
if
(givenString.length() == index && count ==
4
){
ipAddress = ipAddress.substring(
0
,ipAddress.length()-
1
);
result.add(ipAddress);
return
;
}
if
(givenString.length() < index +
1
)
return
;
ipAddress = (ipAddress + givenString.substring(index , index +
1
) +
'.'
);
GetAllValidIpAddress(result, givenString, index +
1
, count +
1
, ipAddress);
ipAddress = ipAddress.substring(
0
,ipAddress.length() -
2
);
if
(givenString.length() < index +
2
||
givenString.charAt(index) ==
'0'
)
return
;
ipAddress = ipAddress + givenString.substring(index,index +
2
) +
'.'
;
GetAllValidIpAddress(result, givenString, index +
2
,
count +
1
, ipAddress);
ipAddress = ipAddress.substring(
0
,ipAddress.length() -
3
);
if
(givenString.length() < index +
3
||
Integer.valueOf(givenString.substring(index,index +
3
)) >
255
)
return
;
ipAddress += givenString.substring(index,index +
3
) +
'.'
;
GetAllValidIpAddress(result, givenString,
index +
3
, count +
1
, ipAddress);
ipAddress = ipAddress.substring(
0
,ipAddress.length()-
4
);
}
public
static
void
main (String[] args) {
String givenString =
"25525511135"
;
ArrayList<String>result =
new
ArrayList<String>() ;
String ipAddress =
""
;
GetAllValidIpAddress(result, givenString,
0
,
0
,ipAddress);
for
(
int
i =
0
; i < result.size(); i++)
System.out.println(result.get(i));
}
}