这道题水,但是就是看不懂题意,加上输入不太会。反正奇数的话,一次取下整,一次取上整,轮着来。
__debug大爷说我肯定做不出来,果然没做出来,%%%__debug
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#define sys system("pause")
const int MAXN=1001;
using namespace std;
string s[MAXN];
int main()
{
int i=0,maxlen=0;
while(getline(cin,s[i++]))
{
maxlen=max(maxlen,(int)s[i-1].size());
}
string first(maxlen+2,'*');
cout<<first<<endl;
bool flag=true;
for(int j=0;j<i-1;j++)
{
printf("*");
int len=maxlen-s[j].size();
string front(len/2,' '),back(len/2,' ');
if(len&1)
{
if(!flag)
{
front+=' ';
cout<<front;
cout<<s[j];
cout<<back;
flag=1;
}
else
{
back+=' ';
cout<<front;
cout<<s[j];
cout<<back;
flag=0;
}
}
else
{
cout<<front;
cout<<s[j];
cout<<back;
}
printf("*\n");
}
cout<<first;
}
。