From 8f6d2399faad6efdf39b462d68a85b6a406b6a90 Mon Sep 17 00:00:00 2001 From: Oliver Lew Date: Tue, 8 Jan 2019 23:45:51 +0800 Subject: [PATCH] improve style --- PATBasic/1027.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/PATBasic/1027.c b/PATBasic/1027.c index 70dd831..0c8de41 100644 --- a/PATBasic/1027.c +++ b/PATBasic/1027.c @@ -41,16 +41,20 @@ int main() char c; int N, M; scanf("%d %c", &N, &c); - - for(M = 1; 2 * M * M - 1 <= N; M++) ; M--; /* determine the size */ - + + for(M = 1; 2 * M * M - 1 <= N; M++) ; + M--; /* determine the size */ + /* draw the sandglass */ - for(int i = 0; i < 2 * M - 1; i ++){ - for(int j = 0; j < M - 1 - ABS(M - 1 - i); j++) putchar(' '); - for(int j = 0; j < 2 * ABS(M - 1 - i) + 1; j++) putchar(c); + for(int i = 0; i < 2 * M - 1; i ++) + { + for(int j = 0; j < M - 1 - ABS(M - 1 - i); j++) + putchar(' '); + for(int j = 0; j < 2 * ABS(M - 1 - i) + 1; j++) + putchar(c); putchar('\n'); } printf("%d", N - 2 * M * M + 1); - + return 0; }