488-triangle Wave
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem &problem=429
In this problem your are to generate a triangular wave form according to a specified pair of amplitude and Frequency.
Input and Output
The input begins with a single positive integer in a line by itself indicating the number of cases following, each of them as described below. This are followed by a blank line, and there are also a blank line between two consecutive.
Each input set would contain two integers, each in a separate line. the amplitude; The second integer is the Frequency.
For each test case, the output must follow the description below. The outputs of two consecutive cases is separated by a blank line.
For the output of your program, you are printing wave forms each separated by a blank line. The total number of waves forms equals the Frequency, and the horizontal ' height ' of each wave equals the amplitude. The amplitude would never be greater than nine.
The waveform itself should is filled with integers on each line which indicate the ' height ' of this line.
Note: There is a blank line after each separate waveform, excluding the last one.
Sample Input
1
3
2
Sample Output
1
333
1
1
333
1
Complete code:
/*0.065s*/
#include <cstdio>
int main (void)
{
int T, A, F;
int I, j, K, L;
scanf ("%d", &t);
for (i = 0; i < T; i++)
{
if (i)
putchar (' \ n ');
scanf ("%d%d", &a, &f);
for (j = 0; J < F; J +)
{
if (j)
Putchar (' \ n ');
for (k = 0; k < A; k++)
{for
(l = 0; l <= k; l++)
Putchar (' 1 ' + K);
Putchar (' \ n ');
}
for (k = A-2 k >= 0; k--)
{for
(l = 0; l <= k; l++)
Putchar (' 1 ' + K);
Putchar (' \ n ')
;
}} return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/