Advertisement
SSemen

Николаев Семён

Mar 18th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. int fmax(int a, int b, int c) {
  7.     int max = 0;
  8.     if (a > max)
  9.         max = a;
  10.     if (b > max)
  11.         max = b;
  12.     if (c > max)
  13.         max = c;
  14.     return max;
  15. }
  16.  
  17. int main() {
  18.  
  19.     int r, g, b;
  20.     cin >> r >> g >> b;
  21.  
  22.     int a = fmax(r, g, b);
  23.     double k = 1 - (a / 255.);
  24.     if (abs(k - 1) < 0.0000000001)
  25.         cout << "0 " << "0 " << "1 " << "0";
  26.     else {
  27.         double c = (1 - r / 255. - k) / (1 - k);
  28.         double m = (1 - g / 255. - k) / (1 - k);
  29.         double y = (1 - b / 255. - k) / (1 - k);
  30.  
  31.  
  32.         cout.precision(4);
  33.         cout << c << " " << m << " " << y << " " << k;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement