2010-03-18 3 views
0

J'ai le code dans lequel je veux savoir le plus grand nombre de six chiffres, le code comme suit,Comment puis-je trouver le plus grand nombre de six chiffres ou plus?

    if((pixels->r == 244 || pixels->g == 242 || pixels->b == 245) || (pixels->r == 236 || pixels->g == 235 || pixels->b == 233) || (pixels->r == 250 || pixels->g == 249 || pixels->b == 247) || (pixels->r == 253 || pixels->g == 251 || pixels->b == 230) || (pixels->r == 253 || pixels->g == 246 || pixels->b == 230) || (pixels->r == 254 || pixels->g == 247 || pixels->b == 229)) 
       { 
        numberOfPixels1++; 
        NSLog(@"Pixel data1 %d", numberOfPixels1); 
       } 
       if((pixels->r == 250 || pixels->g == 240 || pixels->b == 239) ||(pixels->r == 243 || pixels->g == 234 || pixels->b == 229) || (pixels->r == 244 || pixels->g == 241 || pixels->b == 234) || (pixels->r == 251 || pixels->g == 252 || pixels->b == 244) || (pixels->r == 252 || pixels->g == 248 || pixels->b == 237) || (pixels->r == 254 || pixels->g == 246 || pixels->b == 225)) 
       { 
        numberOfPixels2++; 
        NSLog(@"Pixel data2 %d", numberOfPixels2);     } 
       if((pixels->r == 255 || pixels->g == 249 || pixels->b == 225) ||(pixels->r == 255 || pixels->g == 249 || pixels->b == 225) || (pixels->r == 241 || pixels->g == 231 || pixels->b == 195) || (pixels->r == 239 || pixels->g == 226 || pixels->b == 173) || (pixels->r == 224 || pixels->g == 210 || pixels->b == 147) || (pixels->r == 242 || pixels->g == 226 || pixels->b == 151)) 
       { 
        numberOfPixels3++; 
        NSLog(@"Pixel data3 %d", numberOfPixels3); 
       } 

       if((pixels->r == 235 || pixels->g == 214 || pixels->b == 159) ||(pixels->r == 235 || pixels->g == 217 || pixels->b == 133) || (pixels->r == 227 || pixels->g == 196 || pixels->b == 103) || (pixels->r == 225 || pixels->g == 193 || pixels->b == 106) || (pixels->r == 223 || pixels->g == 193 || pixels->b == 123) || (pixels->r == 222 || pixels->g == 184 || pixels->b == 119)) 
       { 
        numberOfPixels4++; 
        NSLog(@"Pixel data4 %d", numberOfPixels4); 
       } 
       if((pixels->r == 199 || pixels->g == 164 || pixels->b == 100) ||(pixels->r == 188 || pixels->g == 151 || pixels->b == 98) || (pixels->r == 156 || pixels->g == 107 || pixels->b == 67) || (pixels->r == 142 || pixels->g == 88 || pixels->b == 62) || (pixels->r == 121 || pixels->g == 77 || pixels->b == 48) || (pixels->r == 100 || pixels->g == 49 || pixels->b == 22)) 
       { 
        numberOfPixels5++; 
        NSLog(@"Pixel data5 %d", numberOfPixels5); 
       } 
       if((pixels->r == 101 || pixels->g == 48 || pixels->b == 32) ||(pixels->r == 96 || pixels->g == 49 || pixels->b == 33) || (pixels->r == 87 || pixels->g == 50 || pixels->b == 41) || (pixels->r == 64 || pixels->g == 32 || pixels->b == 21) || (pixels->r == 49 || pixels->g == 37 || pixels->b == 41) || (pixels->r == 27 || pixels->g == 28 || pixels->b == 46)) 
       { 
        numberOfPixels6++; 
        NSLog(@"Pixel data6 %d", numberOfPixels6); 
       } 

Je dois trouver plus de numberOfPixels1 .... numberOfPixels6 du code ci-dessus. Il existe un moyen optimal pour trouver le plus grand nombre?

+3

Ce code me fait mal à lire. –

Répondre

2

vous avez seulement six valeurs donc dans ce un cas pour la boucle à travers les stockant le plus grand devrait fonctionner assez bien

code pseudo ::

for x in numberOfPixels1...numberOfPixels6 do 
    if x > tmp then 
     tmp = x 
    end 
end 
+0

Ou utilisez simplement la macro 'MAX()': 'tmp = MAX (x, tmp);' –

+0

Merci pour la suggestion Dave. Je n'ai réellement aucune idée réelle de la langue utilisée, d'où le pseudo code. – zellio

1

ne peut pas voir tout motif ici, désolé. Peut-être, si vous avez converti RVB à un autre color space cela pourrait être fait plus simple?

+0

ouais .. moi 2 pense ainsi. – bragboy

Questions connexes