开发者

How i find the greatest number from six or more digit number?

开发者 https://www.devze.com 2022-12-24 09:16 出处:网络
I have the code in which i want to find out the greatest number from six numbers, the code as follows,

I have the code in which i want to find out the greatest number from six numbers, the code as follows,

                 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);
           开发者_高级运维     }

I have to find out greatest from numberOfPixels1....numberOfPixels6 from above code. There are any optimum way to find out the greatest number?


you only have six values so in this case a for loop across them storing the greatest should work well enough

pseudo code::

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


Can't see any pattern here, sorry. Maybe, if you converted RGB to some other color space this could be done simpler?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号