如何确定使用的功能顺序?
How to determine the sequence of functions used?
我目前正在为3位健身房拨号锁编写一个程序。现实生活中的拨号方式是你必须右转到第一个数字,向左转到第二个数字,然后再次向右转到第三个数字。我有看起来像右转和左转的功能。 目前,我正在为我的组合锁编写测试,其中一个测试涉及转向正确的数字,但方向错误(右、右、右,而不是右、左、右(。有没有办法确定使用函数的顺序(例如,使用右转,左转,右转,因此返回1(?
谢谢
一种方式是
enum {RIGHT, LEFT};
int my_combo[]=
{
RIGHT, LEFT, RIGHT, -1 ///-1 is a delimiter in order to test if the end of the array of combo keys.
};
TypeReturn turnLeft(){...}
TypeReturn turnRight(){...}
...
///the function where you are going to test it, for this example return Boolean
/// you change for your need
int entry_combo[]={RIGHT, RIGHT, RIGHT, -1};
/// this could be a while loop too, some people preferred that
bool ret = true;
int i(0);
for(; ;i++)
{
if(entry_combo[i]!= -1 && my_combo[i] !=-1)
{
if(entry_combo[i] != my_combo[i])
{
ret = false;
break;
}
else
{
////here you could put turnLeft or turnRight, depending of what value are in my_combo.
}
}
else
{
ret = (i==0)?true:(entry_combo[i] != my_combo[i])?false:ret)) ; /// you must decide if what to return if the combo key
/// are empty. for me just return true. there are other criteria to choose,
}
}
return ret;
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- CMake-按正确顺序将项目与C运行时对象文件链接
- 函数调用中参数的顺序重要吗
- 为什么不;名字在地图上是按顺序排列的吗
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 带内存和隔离功能的SQLite
- 数到第n个楼梯的路(顺序无关紧要)
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- QML按钮点击功能执行顺序
- 如何确定使用的功能顺序?
- 共享库中静态功能成员的破坏顺序
- 编写一个递归功能,该功能采用数组并以相反顺序显示元素,而无需在末尾启动数组的索引
- 为什么要以相反的顺序执行RUST功能和FFI C 功能
- 变异模板中的功能顺序
- 以特定顺序调用功能
- 是否有可以将每个双精度转换为唯一uint64_t,保持精度和顺序的功能?(为什么我找不到?
- C 17带有运营商超载功能的评估顺序
- 带顺序开关的插入排序功能
- 提升启用/disable_if功能对的顺序重要吗?