题解
2024-03-17 21:48:12
发布于:陕西
9阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1010;
char str[N][N];
int len[N];
int main () {
int cnt = 0,mx = -1;
while(gets(str[cnt])) {
len[cnt] = strlen(str[cnt]);
mx = max(mx,len[cnt]);
cnt++;
}
cnt--;
string a(mx+2,'*');
cout << a << endl;
bool bt = false;
for (int i = 0;i <= cnt;i++) {
cout << '*';
if (len[i] == 0) {
for (int j = 1;j <= mx;j++) cout << " ";
} else {
int mid;
if ((mx - len[i]) % 2 == 1) {
if (bt == false) {
mid = (mx - len[i] - 1) / 2;
for (int j = 1;j <= mid;j++) cout << " ";
cout << str[i];
for (int j = 1;j <= mid+1;j++) cout << " ";
bt = true;
} else {
mid = (mx - len[i] + 1) / 2;
for (int j = 1;j <= mid;j++) cout << " ";
cout << str[i];
for (int j = 1;j <= mid-1;j++) cout << " ";
bt = false;
}
} else {
mid = (mx - len[i]) / 2;
for (int j = 1;j <= mid;j++) cout << " ";
cout << str[i];
for (int j = 1;j <= mid;j++) cout << " ";
}
}
cout << "*\n";
}
cout << a << endl;
return 0;
}
这里空空如也
有帮助,赞一个