UVA_488:Triangle Wave

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:该题关键是格式,每两组之间两个空行,单组之内的三角波之间有一个空行。
时间: 2024-10-13 17:02:12

UVA_488:Triangle Wave的相关文章

UVa 488 - Triangle Wave

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=429 题目:每个例子输入2个数,一个是wave的幅度,一个是重复的个数. 例如:Input1 32 output:122333221 122333221 思路: 将1,22,333,···,999999999.字符串存在数组里.按照幅度打印输出就好.然后注意一

UVa488 - Triangle Wave

对数字输出格式的简单处理 #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; } el

STM32之DAC君

如花说得好:呃呃呃.是俗话说得好:有了ADC,怎可少了DAC..我觉得奇怪.今天我开头就直奔主题了.我想了想,总结了一句话:孙悟空纵然有七十二变.无论是变成猫也好,变成狗也罢.始终还是会变回他本身.所以我怎么的拐弯抹角,还是会回到DAC..这不.前面几句废话,还是回到了讲DAC上来了..好吧.今天就直接一点吧,换个风格的开头. 先来张比如花漂亮的照片.大家请尽情欣赏:因为其够美丽了.所以我就不展现我美丽而销魂的涂鸦了. 鉴赏过之后.我们来看看STM32之DAC的Resume(简历简介): ● 2

Simplest Doppler Radar System

Introduction I've for some time now wanted to do more RF design. Although I have taken some RF design courses, I haven't actually made a single RF design before. But you can't learn without doing and inspired by the MIT coffee can radar designed by G

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

(leetcode题解)Pascal&#39;s Triangle

Pascal's Triangle  Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意实现一个杨辉三角. 这道题只要注意了边界条件应该很好实现出来,C++实现如下 vector<vector<int>> generate(int

Lab 1: Write a java program for the triangle problem and test the program with Junit.

Tasks: 1. Install Junit(4.12), Hamcrest(1.3) with Eclipse 将两个jar包添加到工程中 2. Install Eclemma with Eclipse 3. Write a java program for the triangle problem and test the program with Junit. [Description of triangle problem]Function triangle takes three i

Solution to Triangle by Codility

question: https://codility.com/programmers/lessons/4 we need two parts to prove our solution. on one hand, there is no false triangular. Given the array has been sorted, if A[i]+A[i+1]>A[i+2], we can prove the existence of the triangle. for array A i

LeetCode (13) Pascal&#39;s Triangle (杨辉三角 )

题目描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return 从第三行开始,每行除了最左边和最右边两个数为1,其他数字都是上一行中相邻两个数字之和.根据上述规则可以写出下面的代码: class Solution { public: vector<vector<int> > generateRow1() { vector<in