Hollow TrianglesTime limit:1000/1000ms (java/other) Memory limit:32768/32768k (java/other)Total Submission (s): Accepted submission (s):problem DescriptionBy hollowing out a character triangle, you can save material costs and reduce weight, but the key is to pursue another visual effect. In the design process, you need to give a variety of patterns of material and size of the triangle template, through the computer to do it temporarily, in order to see the effect.
Inputeach line contains one character and one integer n (0<n<41), and the different characters represent different patterns, and the integer n represents the height of the isosceles triangle. The bottom of the 2n-1 is obviously long. If you encounter the @ character, it means that the template triangle you have made is enough. Div <>
OutputA row should be empty between each boilerplate triangle, and the middle of the triangle is empty. Obviously there is no extra space at the end of the line.
Sample Input
X 2A 7@
Sample Output
XXXX a A A A a a a a a a aaaaaaaaaaaaaa
AuthorQiannengIdeas:find a regular problem! First of all, consider the former n-1 row and Nth row is not the same, the nth row all output (a total of 2*n-1 characters), and the former n-1 row need to find the law:The first character is located in N-(i-1), where I is the line I, and the second character is n+ (i-1); (Note: There is no space after the last character!) ), except for these two positions at a location less than or equal to n+ (i-1) are all spaces! Code:
#include <stdio.h> #include <string.h>int main () {char a;int b,i,j,k=0;while ((A=getchar ())! = ' @ ')// Convertible to: while (scanf ("%c", &a) &&a!= ' @ ') {++k;getchar ();//The function of this sentence is to read the blanks! scanf ("%d", &b); GetChar ();//Remember that this sentence cannot be saved, otherwise it will be changed to \ n (line break) at the second input! if (k!=1)//This format is very important, this is the first result after the first output blank line, printf ("\ n");////The output of a blank line only after the second result is satisfied, //This blank line is still before the second result, Satisfies the condition that there is a blank line between two empty triangles! For (i=1;i<b;i++) {for (j=1;j<=b+ (i-1); j + +) {if (j==b-(i-1) | | | j==b+ (i-1)) printf ("%c", a), Else printf ("");} printf ("\ n");} for (i=0;i<2*b-1;i++) printf ("%c", a);p rintf ("\ n");} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1091 Hollow Triangles