CF 5 B. Center Alignment

题目:Center Alignment

思路:模拟

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
char s[1010][1010];
int main()
{
    int cnt=0;
    while(gets(s[cnt++])) ;
    int mx=0;
    for(int i=0;i<cnt;i++)
    {
        int l=strlen(s[i]);
        mx=max(mx,l);
    }
    for(int i=0;i<mx+2;i++)
        cout<<"*";
    cout<<endl;
    bool tag=1;
    int pnt;
    for(int i=0;i<cnt-1;i++)
    {
        cout<<"*";
        int tmp=mx-strlen(s[i]);
        if(tmp%2==1)
            tag=!tag;
        pnt=(tmp+tag)/2;
        for(int j=1;j<=pnt;j++)
            cout<<" ";
        cout<<s[i];
        for(int j=1;j<=tmp-pnt;j++)
            cout<<" ";
        cout<<"*"<<endl;
    }
    for(int i=0;i<mx+2;i++)
        cout<<"*";
    cout<<endl;
    return 0;
}
View Code

 

posted @ 2013-07-13 15:59  over_flow  阅读(256)  评论(0编辑  收藏  举报