Do title records --day35

 PAT B1036 

No problem itself difficulties, attention ternary operator shorthand easy to confuse yourself in this position 0, or less, there is a real determination parity with% but len ​​is /, the question itself is not difficult, take note of it

A rounding is odd plus n / 2 + 1

#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    int n;
    char c;
    while(scanf("%d",&n)!=EOF)
    {
    getchar();
    scanf("%c",&c);
    int len=(n%2)?(n/2+1):(n/2);
    //printf("len=%d\n",len);
    for(int i=1;i<=len;i++)
    {
        if(i==1||i==len)
        {
            for(int j=1;j<=n;j++)
                printf("%c",c);
        }
        else
        for(int j=1;j<=n;j++)
        {
            if (j==1||j==n)
                printf("%c",c);
            else
                printf(" ");
        }
        printf("\n");
    }
    }
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/tingxilin/p/11299331.html