我有一个关于目标c和条件的小问题。我们如何证明,在我给出的6个条件下,至少有3个条件必须被验证为正确?
谢谢你的回答!
发布于 2013-03-20 01:14:10
int counter = 0;
if (condition1) counter++;
if (condition2) counter++;
if (condition3) counter++;
if (condition4) counter++;
if (condition5) counter++;
if (condition6) counter++;
if (counter >= 3) {
// something
}发布于 2013-03-20 01:13:40
你可以这样做:
int validated=0;
if(condition1){
validated++;
}
if(condition2){
validated++;
}
if(condition3){
validated++;
}
if(condition4){
validated++;
}
if(condition5){
validated++;
}
if(condition6){
validated++;
}
if(validated>=3){
//do your stuffs
}发布于 2013-03-20 01:14:52
您可以尝试计算正确的条件:
伪代码:
int counter = 0;
if(A) counter++;
if(B) counter++;
if(C) counter++;
if(D) counter++;
if(E) counter++;
if(F) counter++;
if(counter >= 3){
//do stuff here
}
counter = 0;https://stackoverflow.com/questions/15506095
复制相似问题