我需要一个计数器algortihm,它使用任意给定的数字进行计数.
我的代码与此类似:
static char digits[] = {'x','y','z'}; /* Arbitrary number of arbitrary digits. */
int i;
for(i=0; i<100; i++) {
printf("%s\n", get_next());
}
Run Code Online (Sandbox Code Playgroud)
我的预期产量:
x
y
z
yx
yy
yz
zx
zy
zz
yxx
yxy
yxz
yyx
yyy
yyz
yzx
yzy
yzz
zxx
... and so on
Run Code Online (Sandbox Code Playgroud)
如你所见,我需要算法来实现get_next()函数,所以使用C语言不是重点.
编辑我以澄清目的:
我的get_next()函数可能与此类似:
char get_next() {
static previous = digits[0];
char *next_number;
/* do something here using previous and digits[] */
return next_number;
}
Run Code Online (Sandbox Code Playgroud)
请注意,使用get_next(void)或 …
我正在开发一个关于ROR的应用程序,它具有不同的状态,并且基于条件状态将会改变.我已经在状态机上搜索了很多东西,我找到了用于实现状态机的好库,但我正在寻找教程或示例代码,所以我可以通过它,请帮助我解决这个问题.
我找到了state_machine和AASM插件,但我对他们给出的文档不满意,我正在研究更多的例子,请帮助.
我想将Azure Queues用作高负载/高规模Web服务的状态机.
客户端将向Web服务端点提交请求,此时我将返回请求ID.
然后,我将消息提交到队列,以便工作者角色可以处理它,但在提交过程中不会发生数据库活动.相反,我想使用消息所在的队列来表示它的当前状态.
我的问题是,如果一个辅助角色从队列中抓取消息来处理它,它就会在该队列上变得不可见.如果我想检查该消息的处理状态,我的消息状态不明确.消息丢失/从未收到,或者它在队列中但是因为正在处理而不可见.
理想情况下,我希望能够在隐形信息中达到顶峰.如果我找到一个与请求ID匹配的,我知道它正在被处理,如果它是不可见的,或者它正在等待处理,如果它是可见的.显然,我知道它何时完成处理,因为该操作将导致数据库写入.
这是可能的,或者是我无法查看Azure队列中的不可见消息,这是不是?
class Strength(State):
def run(self, gamedata):
print("You have 100 points to assign to your character.\n Start now to assign those Points to your characters strength, agility, speed and defense.")
strenghtwert = int(input("STRENGTH: >>"))
return AGILITY, gamedata, strenghtwert
def next(self, next_state):
if next_state == AGILITY:
return CreatePlayer.agility
class Agility(State):
def run(self, gamedata,strenghtwert):
agilitywert = int(input("AGILITY: >>"))
return SPEED, gamedata, strenghtwert, agilitywert
def next(self, next_state):
if next_state == SPEED:
return CreatePlayer.speed
Run Code Online (Sandbox Code Playgroud)
执行此操作时,出现错误:ValueError: too many values to unpack (expected 2)。我认为错误是return AGILITY, …
我已经用“using”关键字声明了函数指针的别名,但我不知道如何使用该别名。
在类UpdateState的函数中Person,我想替换m_state与当前状态和要转换到下一个状态相对应的函数的返回值。但是,以下错误发生在第 38 行Person.cpp,我不知道如何纠正该行。我认为我错误地使用了别名数组。
error C2064: term does not evaluate to a function taking 1 arguments
Run Code Online (Sandbox Code Playgroud)
人.h
error C2064: term does not evaluate to a function taking 1 arguments
Run Code Online (Sandbox Code Playgroud)
人物.cpp
#pragma once
enum STATE
{
A,
B,
C,
D,
E,
STATE_NUM,
};
class Person
{
public:
Person();
~Person();
void UpdateState();
STATE IsInStateA(char nextState);
STATE IsInStateB(char nextState);
STATE IsInStateC(char nextState);
STATE IsInStateD(char nextState);
STATE IsInStateE(char nextState);
private:
STATE m_state;
};
Run Code Online (Sandbox Code Playgroud)