1036 跟奥巴马一起编程 (15分)

整数除以2进行四舍五入的操作可以通过判断它是否是奇数来解决,以避免浮点数的介入。

int n;

int main()
{
    char c;
    cin>>n>>c;

    int m;
    if(n & 1) m=n/2+1;
    else m=n/2;

    for(int i=0;i<m;i++)
    {
        if(!i || i == m-1)
            for(int j=0;j<n;j++) cout<<c;
        else
        {
            cout<<c;
            for(int j=0;j<n-2;j++) cout<<' ';
            cout<<c;
        }
        cout<<endl;
    }
    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14337615.html