Vui*_*inh 11 c c++ algorithm optimization conditional
目前我可以运行我的程序,但我的代码包含很多重复,看起来像:
while(option != 'E' && option != 'D' && option != 'P' && option != 'Q' &&
option != 'e' && option != 'd' && option != 'p' && option != 'q') {
// Some code here
}
Run Code Online (Sandbox Code Playgroud)
要么:
while(cType != 'S' && cType != 'L' && cType != 'O' && cType != 'Q' &&
cType != 's' && cType != 'l' && cType != 'o' && cType != 'q') {
// Some code here
}
Run Code Online (Sandbox Code Playgroud)
缩短上述代码的最快方法是什么?
(除了使用附加功能有什么办法吗?)
const char invalidChars[] = "edpq";
while (strchr(invalidChars, tolower(option)) != 0) {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
359 次 |
| 最近记录: |