【UVA】【第0章】488 - Triangle Wave

 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


本题很简单 但是不知道UVA上通过率怎么那么低- -

先输入T

表示有T列波

然后每次读入振幅和频率(如果这真的是频率的话)

然后简单处理

输出

注意要判断如果是最后一列波的最后一个频率(如果这叫频率的话)的最后一个点

就不能输出'\n'了

代码如下

#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int T, A, F;

void init_file()
{
	freopen("White_GS_9.in", "r", stdin);
	freopen("White_GS_9.out", "w", stdout);
}

void read_data()
{
	scanf("%d\n", &T);
	while(T--)
	{
		scanf("%d%d", &A, &F);
		for(int i = 1; i <= F; i++)
		{
			for(int j = 1; j <= 2 * A; j++)
			{
				for(int k = 1; k <= (j <= A ? j : (2 * A - j)); k++)
				{
				  printf("%d", (j <= A ? j : (2 * A - j)));
				}
				if(T == 0 && i == F && j == 2 * A);
				else
				printf("\n");
			}	
		}
	}
}

void work()
{

}

int main()
{
  init_file();
  read_data();
  work();
  return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 根据三角形不等式,我们可以编写一段C语言代码来判断三条线段的长度能否组成三角形,如果不能,则输出No,如果能,请判断此三角形是否为等边三角形,若是则输出E-Triangle,否则输出G-Triangle。以下是编写的C语言程序:#include<stdio.h> int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); if(a+b>c && a+c>b && b+c>a) { if(a==b && a==c) printf("E-Triangle"); else printf("G-Triangle"); } else printf("No"); return 0; } ### 回答2: 可以通过以下步骤来判断三条线段能否组成三角形,并判断是否为等边三角形: 1. 首先,输入三个整数表示三条线段的长度,分别为a、b和c。 2. 判断三个数是否大于0,若有任一条线段长度小于等于0,则输出"No"。 3. 判断是否满足三角形的三边关系,即任意两边之和大于第三边。若不满足该条件,则输出"No"。 4. 判断是否为等边三角形,若三个数都相等,则输出"E-Triangle";否则,输出"G-Triangle"。 以下是对应的C语言代码实现: ```c #include<stdio.h> int main() { int a, b, c; // 输入三个整数 printf("请输入三个整数,分别表示三条线段的长度:\n"); scanf("%d%d%d", &a, &b, &c); // 判断三角形是否合法 if (a <= 0 || b <= 0 || c <= 0 || (a+b <= c) || (a+c <= b) || (b+c <= a)) { printf("No\n"); } else { // 判断是否为等边三角形 if (a == b && b == c) { printf("E-Triangle\n"); } else { printf("G-Triangle\n"); } } return 0; } ``` 该程序首先通过`scanf`函数输入三个整数,判断是否满足三角形的三边关系,并判断是否为等边三角形,并输出相应结果。 ### 回答3: 可以根据三角形的性质来判断三条线段能否组成一个三角形。三角形的任意两边之和大于第三边,任意两边之差小于第三边。所以我们可以编写一个判断三角形的函数。再判断是否为等边三角形。 首先,定义一个函数isTriangle(int a, int b, int c),用于判断三条边a、b、c能否组成一个三角形: ```c int isTriangle(int a, int b, int c) { if (a + b > c && a + c > b && b + c > a) { return 1; } else { return 0; } } ``` 再定义一个函数isEquilateral(int a, int b, int c),用于判断三角形是否为等边三角形: ```c int isEquilateral(int a, int b, int c) { if (a == b && b == c) { return 1; } else { return 0; } } ``` 在主函数中,读入三个整数表示三条线段的长度,调用isTriangle函数判断是否为三角形,如果不是则输出"No",否则调用isEquilateral函数判断是否为等边三角形,如果是则输出"E-Triangle",否则输出"G-Triangle"。 ```c #include <stdio.h> int isTriangle(int a, int b, int c) { if (a + b > c && a + c > b && b + c > a) { return 1; } else { return 0; } } int isEquilateral(int a, int b, int c) { if (a == b && b == c) { return 1; } else { return 0; } } int main() { int a, b, c; printf("请输入三条线段的长度:"); scanf("%d %d %d", &a, &b, &c); if (!isTriangle(a, b, c)) { printf("No\n"); } else if (isEquilateral(a, b, c)) { printf("E-Triangle\n"); } else { printf("G-Triangle\n"); } return 0; } ``` 以上就是判断三条线段是否能组成三角形以及是否为等边三角形的C语言程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值