Hatena::Grouptopcoder

TopCoderの問題を解く

解いた問題の一覧表

2009-08-30

RGBColor

| 15:54

問題文, SRM 176

補色を返す。

224.33/250

class RGBColor {
public:
    vector <int> getComplement(vector <int> rgb) {
        vector <int> result(3);
        result[0] = 255 - rgb[0];
        result[1] = 255 - rgb[1];
        result[2] = 255 - rgb[2];
        if (abs(rgb[0]-result[0])<=32 && abs(rgb[1]-result[1])<=32 
                && abs(rgb[2]-result[2])<=32) {
            result[0] = (rgb[0]+128 <= 255) ? rgb[0]+128: rgb[0]-128;
            result[1] = (rgb[1]+128 <= 255) ? rgb[1]+128: rgb[1]-128;
            result[2] = (rgb[2]+128 <= 255) ? rgb[2]+128: rgb[2]-128;
        }
        return result;
    }
};