Skip to content

Instantly share code, notes, and snippets.

@drelagreen
Created November 18, 2018 19:32
Show Gist options
  • Save drelagreen/bd5ba1f0f5ebcaf831d9a12c3fb3b060 to your computer and use it in GitHub Desktop.
Save drelagreen/bd5ba1f0f5ebcaf831d9a12c3fb3b060 to your computer and use it in GitHub Desktop.
Codeforses - MAILRUCUP 3 (B)
import java.io.IOException;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
StringBuilder str = new StringBuilder(s.nextLine());
int i1=0;
StringBuilder xxx = new StringBuilder();
for (int i = 1; i <= 5; i++) {
double kek = (double) str.length() / i;
if (kek <= 20) {
if (i == 1) {
System.out.println(str);
break;
}else if(kek%1==0) {
String[] mass = str.toString().split("");
for (int j = 0; j < mass.length; j++) {
if (j%kek==0&&j!=0) xxx.append("\n");
xxx.append(mass[j]);
}
System.out.println(xxx);
break;
}else {
ArrayList<String> list = new ArrayList<>(Arrays.asList(str.toString().split("")));
if (i1==0) list.add(0, "*"); else
list.add(i1*(int)kek+1, "*");
i1++;
if (i1>i) i1=0;
str = new StringBuilder();
for (String s2 : list) {
str.append(s2);
}
i--;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment