当前位置:网站首页>Triangle problem worst case test case
Triangle problem worst case test case
2022-07-20 08:31:00 【The eagle is chirping】
Triangle problem worst-case test case calculation
Input 3 It's an integer a、b and c As the three sides of a triangle , requirement a、b and c The following conditions must be met :
1、 Integers
2、3 Number
3、 The side length is greater than or equal to 1, Less than or equal to 100
4、 The sum of any two sides is greater than the third
Output is 5 One of the three situations :
If you don't do that 1、2、3, Then the program output is “ Input error ”.
If you don't do that 4, Then the program output is “ Non triangle ”.
If the three sides are equal , Then the program output is “ Equilateral triangle ”.
If exactly two sides are equal , Then the program output is “ an isosceles triangle ”.
If all three sides are not equal , Then the program output is “ General triangle ”.
Algorithm description
take a,b,c The three sides are regarded as vectors vec(a,b,c), The data to be tested is saved in the array a in , that The vector becomes vec(a[i],a[j],a[k]). In this case a Stored in is 1,2,50,99,100, therefore i、j、k The numbers that make up ijk It can be regarded as a pental number , Change this hexadecimal number from 000 Traversing 444 We can work out vec All results
#include<iostream>
using namespace std;
int add(int a[],int n){
int j = 0;
while(a[j]<5&& j<n){
if(a[n-j-1]+1<5){
a[n-j-1] +=1;
return 1;
}else{
a[n-j-1] = 0;
j++;
}
}
return 0;
}
void print(int a[], int n){
for(int i= 0;i<n;i++){
printf("%d ",a[i]);
}
printf("\n");
}
int main(){
int vec[6],count[6];
int v;
int j = 0,left,right;
int a[5];
cout<<" Please enter the number of variables : ";
cin>>v;
cout<<" Please enter the left boundary : ";
cin>>left;
cout<<" Please enter the right boundary : ";
cin>>right;
for(int i = 0;i<v;i++){
count[i] = 0;
}
a[0] = left;
a[1] = left+1;
a[2] = (right+left)/2;
a[3] = right-1;
a[4] = right;
do{
for(int i=0;i<v;i++){
vec[i] = a[count[i]];
}
print(vec,v);
}while(add(count,v));
}
·
边栏推荐
猜你喜欢
【学习笔记】Unreal(虚幻)4引擎入门(四)
Function recursion in C program
Zabbix Server Ping链路监控,状态改变后通过邮件告警
有趣的扫雷游戏,C语言编程实现
Interval coverage problem
Recursive backtracking - maze walking
Zabbix-Sender 增加自定义监控项-- Ping 到目的地链路监控--bat脚本循环运行
Yolo series target detection data set
STM32-仿真调试时的SystemInit陷阱
What if the game needs to be reinstalled after the steam folder is moved
随机推荐
YOLOv5苹果香蕉检测
枚举(enum)奇妙的使用、联合体(共用体union)对空间节省的巧妙
函数指针
SSM notes
YOLOv5实现火焰和烟雾检测
三子棋(N子棋)C语言编程实现,超详细讲解
Pytorch implements retinanet (III) definition and training of loss
YOLOv5飛鳥檢測
Zabbix Server Ping链路监控,状态改变后通过邮件告警
位运算——异或
数据的表示和运算
数据在内存中存储是怎样的?
第七十四篇:机器学习优化方法及超参数设置综述
[Day.2]约瑟夫环问题,如何用数组代替循环链表(详解)
4000字,让你明白递推及其例题做法(C语言,有图)
珍惜时间,提高效率
Heap sorting and heap related operations
Pointer operation exercises and string functions
Yolov5 détection des oiseaux
2021 underwater acoustic target detection summary -rank2