Description
在這個問題中,根據所給的振幅(Amplitude)及頻率(Frequency),你的程式要產生這樣的波。
In this problem you are to generate a triangular wave form according to a specified pair of Amplitude and Frequency.
Input (From File: input.txt)
輸入的第一列有一個整數 n,代表有幾組測試資料。接下來每組測試資料有2列,各有1個正整數(A、F),A代表振幅(A ≤ 9),F代表頻率。 第一列以及各組測試資料間皆有一空白行。請參考Sample input。
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 positive integers, each on a separate line. The first integer is the Amplitude; the second integer is the Frequency.
Output (To File: output.txt)
每組測試資料請輸出 F 個波,每個波振幅的水平高度為 A。波本身是以其"高度"的內容所組成。每個波之間以一空白行分隔開來。 測試資料間也以一空白行分開。 請參考 sample output。
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.
Sample Input 1
2
3
2
5
3
Sample Output 1
1
22
333
22
1
1
22
333
22
1
1
22
333
4444
55555
4444
333
22
1
1
22
333
4444
55555
4444
333
22
1
1
22
333
4444
55555
4444
333
22
1
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *ipf = fopen("input.txt", "r");
FILE *opf = fopen("output.txt", "w");
int t;
fscanf(ipf,"%d",&t);
int i = 0;
int a,b;
int ma=0,mb=0,an=0,bn=0;
int c,c1,c2,max = 0,ans = 0;
for(int i = 0; i<t;i++){
fscanf(ipf,"%d",&a);
fscanf(ipf,"%d",&b);
for(int k = 0; k<b;k++){
for(int i = 1;i<=a;i++){
for(int j = 1; j<=i;j++){
fprintf(opf,"%d",i);
}
fprintf(opf,"\\n");
}
for(int i=a-1; i>=1;i--){
for(int j = 1; j<=i;j++){
fprintf(opf,"%d",i);
}
fprintf(opf,"\\n");
}
fprintf(opf,"\\n");
}
}
fclose(ipf);
fclose(opf);
return 0;
}