Triangle Wave |
In this problem you are to generate a triangular wave form according to a specified pair ofAmplitude and Frequency.
Input and Output
The input begins with a single positive integer on a line by itself indicatingthe number of the cases following, each of them as described below. This line isfollowed by a blank line, and there is also a blank line between two consecutiveinputs.
Each input set will contain two integers, each on a separate line. The first integer is the Amplitude; thesecond integer is the Frequency.
For each test case, the output must follow the description below. The outputs oftwo 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 waveequals 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 thatline.
NOTE: There is a blank line after each separate waveform, excluding the last one.
Sample Input
1 3 2
Sample Output
1 22 333 22 1 1 22 333 22 1
这题大意就是按照给定的格式(如样例)输出,要注意的只有空行了,在每个样例之间及在每个三角波之间都要有个空行,其他不能有空行。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
using namespace std;
int main() {
int Case;
cin >> Case;
while (Case--) {
int a;
int b;
cin >> a >> b;
while (b--) {
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= i; j++) {
cout << i;
}
cout << endl;
}
for (int i = a-1; i > 0; i--) {
for (int j = i; j > 0; j--) {
cout << i;
}
cout << endl;
}
if (b)
cout << endl;
}
if (Case)
cout << endl;
}
return 0;
}