当前位置:网站首页>三角形问题最坏情况测试测试用例
三角形问题最坏情况测试测试用例
2022-07-19 05:03:00 【老鹰嘤嘤】
三角形问题最坏情况测试测试用例计算
输入3个整数a、b和c分别作为三角形的三条边,要求a、b和c必须满足以下条件:
1、整数
2、3个数
3、边长大于等于1,小于等于100
4、任意两边之和大于第三边
输出为5种情况之一:
如果不满足条件1、2、3,则程序输出为“输入错误”。
如果不满足条件4,则程序输出为“非三角形”。
如果三条边相等,则程序输出为“等边三角形”。
如果恰好有两条边相等,则程序输出为“等腰三角形”。
如果三条边都不相等,则程序输出为“一般三角形”。
算法描述
将a,b,c三条边看作向量vec(a,b,c),将要测试的数保存在数组a中,那么 向量就变为vec(a[i],a[j],a[k])。在本例中a中存放的为1,2,50,99,100,于是i、j、k组成的数字ijk可以看成五进制数,将这个五进制数从000遍历到444就可以求出 vec所有结果
#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<<"请输入变量个数: ";
cin>>v;
cout<<"请输入左边界: ";
cin>>left;
cout<<"请输入右边界: ";
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));
}
·
边栏推荐
猜你喜欢
YOLOv5飛鳥檢測
pytorch 目标检测 coco API 讲解 数据生成
idea svn主干合并分支版本Missing ranges异常Error:svn: E195016
Input text to automatically generate images, it's so fun!
Opencv image processing --------- environment installation configuration
PC website realizes wechat code scanning login function (I)
SSM notes
Jenkins linked flybook pushes the test report notification message in the form of signature verification
URL地址映射配置
【YOLOv5实现玩手机检测】
随机推荐
pytorch 数据增强cutmix的实现
Jenkins linked flybook pushes the test report notification message in the form of signature verification
pytorch 实现数据增强分类 albumentations的使用
Mongo sort exceeds maximum memory error
2021 underwater acoustic target detection summary -rank2
JSON数据开发
pytorch 目标检测竞赛(一)数据分析
pytorch 目标检测数据处理(二)提取困难样本,低ap样本
Pytorch yolo5 training any training set
Basic page status code
[signal conditioning] sharing practical experience of building CE amplifier with "crystal triode"
基于STM32F103,用蜂鸣器播放歌曲
整数的分划问题
常见网络厂商Mib库文件
SSM notes
PyQt5快速开发与实战.pdf分享
Openwrt manually installs the netdata plug-in
Pytorch yolo4 training any training set
Basic introduction to multithreading (with sample code)
The gratitude and resentment between the four swordsmen and code review: "abandon all chaos" to "prodigal son returns"