488 - Triangle Wave

In this problem you 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 on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Each input set will contain two integers, each on a separate line. The first integer is 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 will be separated by a blank line.

For the output of your program, you will be printing wave forms each separated by a blank line. The total number of wave forms equals the Frequency, and the horizontal ``height'' of each wave equals the Amplitude. The Amplitude will never be greater than nine.

The waveform itself should be filled with integers on each line which indicate the ``height'' of that line.

NOTE: There is a blank line after each separate waveform, excluding the last one.

在这个问题中,根据所给的振幅(Amplitude)及频率(Frequency),你的程式要产生这样的波。

Input

输入的第一列有一个整数n,代表有几组测试资料。接下来每组测试资料有2列,各有1个正整数(A、F),A代表振幅(A<=9),F代表频率。

第一列以及各组测试资料间皆有一空白行。请参考Sample input。

Output

每组测试资料请输出F个波,每个波振幅的水平高度为A。波本身是以其"高度"的内容所组成。每个波之间以一空白行分隔开来。

测试资料间也以一空白行分开。

Sample Input

1

3
2

Sample Output

1
22
333
22
1

1
22
333
22
1

解题思路:唯一要注意的是两组数据之间的空行和数据内部的空行是不同的

#include<stdio.h>
int main()
{int n,a,f,i,j,t,b;
scanf("%d",&n);
while(n--){
           scanf("%d%d",&a,&f);
           if(a==0&&f==0)break;
           for(i=0;i<f;i++){
                            for(j=1;j<2*a;j++){
                                               if(j>a){
                                                       t=a-(j-a);
                                                       b=t;
                                                       }
                                               else {
                                                    t=j;
                                                    b=t;
                                                    }
                                               while(t--)
                                               printf("%d",b);
                                               printf("\n");
                                               }
                                               if(i!=f-1)printf("\n");
                            }
           if(n!=0)printf("\n");
           }
return 0;
    }


 

posted on 2013-02-06 11:04  喂喂还债啦  阅读(268)  评论(0编辑  收藏  举报