fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. #define MAXL 5
  6. #define MAXC 4
  7. #define BackColor 2
  8. int main() {
  9. int image1[MAXL][MAXC]=
  10. {
  11. {2,3,2,2},
  12. {2,2,2,2},
  13. {2,255,2,2},
  14. {255,2,2,2},
  15. {2,255,2,2}
  16. };
  17.  
  18. std::vector<int> result;
  19. for (int i = 0; i<MAXL;i++)
  20. {
  21. for (int j=0; j<MAXC;j++)
  22. {
  23. if (image1[i][j] != BackColor) // Notice !=
  24. {
  25. result.push_back(i+1);
  26. result.push_back(j+1);
  27. result.push_back(image1[i][j]);
  28. }
  29. }
  30. }
  31.  
  32.  
  33. for (auto x : result)
  34. {
  35. std::cout << x << " ";
  36. }
  37. std::cout << endl;
  38. return 0;
  39. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1 2 3 3 2 255 4 1 255 5 2 255