Algorithm


B. Center Alignment
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.

You are to implement the alignment in the shortest possible time. Good luck!

Input

The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.

Output

Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.

Examples
input
Copy
This  is

Codeforces
Beta
Round
5
output
Copy
************
* This is *
* *
*Codeforces*
* Beta *
* Round *
* 5 *
************
input
Copy
welcome to the
Codeforces
Beta
Round 5

and
good luck
output
Copy
****************
*welcome to the*
* Codeforces *
* Beta *
* Round 5 *
* *
* and *
* good luck *
****************



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <iostream>
#include <vector>


int main(){

    std::string temp; 
    std::vector<std::string> lineVec; 
    int maxSize(0);

    while(getline(std::cin, temp)){
        lineVec.push_back(temp);
        if(temp.size() > maxSize){maxSize = temp.size();}
    }


    bool addLeft(0);
    for(int p = 0; p < maxSize + 2; p++){printf("*");}; puts("");

    for(int p = 0; p < lineVec.size(); p++){
        std::string current = lineVec[p];
        int totalSpace = (maxSize - current.size());
        int leftSpace  = totalSpace / 2;
        int rightSpace = totalSpace / 2;
        if(totalSpace % 2){
            if(addLeft){++leftSpace;} else{++rightSpace;}
            addLeft = 1 - addLeft;
        }

        printf("*");
        for(int q = 0; q < leftSpace; q++){printf(" ");}
        std::cout << current;
        for(int q = 0; q < rightSpace; q++){printf(" ");}
        printf("*\n");

    }

    for(int p = 0; p < maxSize + 2; p++){printf("*");}; puts("");



    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
This is
Codeforces
Beta
Round
5

Output

x
+
cmd
************
* This is *
* *
*Codeforces*
* Beta *
* Round *
* 5 *
************
Advertisements

Demonstration


Codeforces Solution-B. Center Alignment-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+