簡體   English   中英

我如何讓DFA循環播放

[英]How would I get my DFA to loop

我正在編寫一個程序,以檢查用戶輸入的字符串是否為有效的文字。

我的問題是我將如何循環考慮數字(即0,...,9)。 用戶可以輸入任意數量的數字或根本不輸入數字。

到目前為止,我一直在研究案例1:

case 0: if(str[i] == '+' || '-'){ // if first char in the array = (null, +, -)
               s=1; // pass test case -> move to next test case
               i++; // move to next char in the string
        }
        else if (str[i] != '+' || '-'){goto a1;} // this case is the null test case -> moves to next test case; string still not a failure
        else // fail test case -> the string is automatically a failure
            done=true; break;

case 1: a1: if(str[i] >= '0' && str[i] <= '9'){ // if next char in the array = (null, 0, ..., 9)
     //HERE: how to make a loop check for however many numbers user has input.
               s=2;
               i++;
             }
             else if (str[i] != (str[i] >= '0' && str[i] <= '9')){goto a2;}
             else
                 done=true; break;

我正在考慮使用一個簡單的for循環。

哇, goto S,已經有一段時間。

Anwyay,您可以執行以下操作:

std::all_of(str.cbegin(), str.cend(), [](char c){return std::isdigit(c);});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM