码迷,mamicode.com
首页 > 其他好文 > 详细

UVA_488:Triangle Wave

时间:2015-04-02 22:13:43      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

PS: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.

Sample Input
3
2
Sample Output
1
22
333
22
1


1
22
333
22
1

Language:C++ 4.8.2


#include<stdio.h> 
int main(void)
{
    int m, n, total;
    int copy_i;
    scanf("%d", &total);
    while(total--)
    {
        scanf("%d%d", &m, &n);
        while(n--)
        {
            for(int i = 1; i <= m; i++)
            {
                copy_i = i;
                while(copy_i--)
                    printf("%d", i);
                printf("\n");
            }
            for(int i = m-1; i >=1; i--)
            {
                copy_i = i;
                while(copy_i--)
                    printf("%d", i);
                printf("\n");
            }
            if(n) // there is a blank line after each separate waveform, excluding the last one.
                printf("\n");
        }
        if(total) // 同上,缺少的话WA。
            printf("\n");
    }
    return 0;
}

// 再PS:该题关键是格式,每两组之间两个空行,单组之内的三角波之间有一个空行。

 

UVA_488:Triangle Wave

标签:

原文地址:http://www.cnblogs.com/xpjiang/p/4388431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!