-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathb.cpp
More file actions
42 lines (40 loc) · 1.07 KB
/
b.cpp
File metadata and controls
42 lines (40 loc) · 1.07 KB
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
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
int main(){
string x;
vector<string> text;
int maxSize = 0;
bool alternate = false;
while(getline(cin, x)){
maxSize = max(maxSize, (int)x.length());
text.push_back(x);
}
for(int i = 0; i < maxSize + 2; i++) cout << '*';
cout << endl;
for(int i = 0; i < text.size(); i++){
cout << '*';
int diff = maxSize - text[i].length();
if(diff % 2 == 0){
for(int j = 0; j < diff / 2; j++){
cout << ' ';
}
cout << text[i];
for(int j = 0; j < diff / 2; j++){
cout << ' ';
}
}else{
for(int j = 0; j < diff / 2 + alternate; j++){
cout << ' ';
}
cout << text[i];
alternate = !alternate;
for(int j = 0; j < diff / 2 + alternate; j++){
cout << ' ';
}
}
cout << '*' << endl;
}
for(int i = 0; i < maxSize + 2; i++) cout << '*';
cout << endl;
return 0;
}