排版题.输出排列成菱形的字母
Time Limit:1s Memory Limit:1000k
Total Submit:10078 Accepted:5422
Problem
用英文大写字母排列出一个三角形
Input
一个整数N (0<N<27)
Output
一个有N行的,由英文大写字母A..Z排列的三角形
Sample Input
3
Sample Output
A BBB CCCCC
C的求解及答案
#include <stdio.h>
#include <stdlib.h>
int main()
{
int N, i, j, pos = 0;
char ch = 'A';
char *buffer;
scanf("%d", &N);
buffer = (char*) malloc(N * N);
for(i = 0; i < N; i++){
for(j = 0; j < N - 1 - i; j++) buffer[pos++] = ' ';
for(j = 0; j <= (i << 1); j++) buffer[pos++] = ch;
buffer[pos++] = '/n';
ch ++;
}
buffer[pos] = 0;
printf("%s", buffer);
free(buffer);
return 0;
}
Memory: 44K
Time: 0ms