fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Pixel {
  5. unsigned char a, r, g, b;
  6. } ;
  7.  
  8. int main() {
  9. const int length = 128;
  10. Pixel image_data[length];
  11. unsigned int i;
  12. unsigned int p;
  13. float factor;
  14.  
  15. cin>>p;
  16. cout<<"Result="<<(unsigned int)(p * 0.5)<<endl;
  17.  
  18. for ( i = 0; i < length; i++ )
  19. {
  20. if ( image_data[i].a == 0 )
  21. image_data[i].r = image_data[i].g = image_data[i].b = 0;
  22. else //if ( image_data[i].a < 255 ) //you don't need this check if a is 8-bit unsigned
  23. {
  24. image_data[i].r = (unsigned short)image_data[i].r * image_data[i].a >> 8;
  25. image_data[i].g = (unsigned short)image_data[i].g * image_data[i].a >> 8;
  26. image_data[i].b = (unsigned short)image_data[i].b * image_data[i].a >> 8;
  27. }
  28. }
  29.  
  30. // your code goes here
  31. return 0;
  32. }
Success #stdin #stdout 0s 16064KB
stdin
5
stdout
Result=2