您的位置:首页 > 其它

UVA 488 10038 10107 10370

2015-03-02 21:05 351 查看
488:

Triangle Wave

Time Limit: 3000MSMemory Limit: Unknown64bit IO Format: %lld & %llu
Submit Status

Description







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.

Sample Input

1

3
2

Sample Output

1
22
333
22
1

1
22
333
22
1


解题思路:

这道题完全是看算法笔记的时候,照着他的例题刷的,没有什么技巧,就是在打印空行上面,WA了好几次。。。

代码:

# include<cstdio>

int main(void)
{
    int N;
    scanf("%d", &N);
    for(int i=0; i<N; i++)
    {
        int A, F;
        scanf("%d%d", &A, &F);
        for(int k1=0; k1<F; k1++)
        {
            for(int k2=1; k2<=A; k2++)
            {
                for(int k3=1; k3<=k2; k3++)
                    printf("%d", k2);
                printf("\n");

            }
            for(int k4=A-1; k4>=1; k4--)
            {
                for(int k5=1;k5<=k4;k5++)
                    printf("%d", k4);
                printf("\n");
            }
            if(k1!=F-1)
                printf("\n");
        }
        if(i != N-1)
            printf("\n");
    }
    return 0;
}
10038:

解题思路:

代码:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: