fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. typedef vector<vector<unsigned>> matrix;
  7. //Not best practice code, but... well. ;-)
  8. matrix check_possibilities(const matrix& input) {
  9. matrix result; result.reserve(input.size());
  10. for(const auto row : input) {
  11. result.emplace_back();
  12. unsigned temp = 0;
  13. for(auto it = row.crbegin(); it != row.crend(); ++it) {
  14. if(*it == 0)
  15. temp += 1;
  16. else //*it = 1
  17. temp = 0;
  18. result.back().push_back(temp);
  19. }
  20. reverse(begin(result.back()), end(result.back()));
  21. }
  22. return result;
  23. }
  24.  
  25. int main() {
  26. matrix input;
  27. for(unsigned i = 0; i < 5; ++i) {
  28. input.emplace_back(5);
  29. for(auto& x : input.back())
  30. cin >> x;
  31. }
  32. matrix right_minimum = check_possibilities(input);
  33. cout << '\n';
  34. for(const auto& row : right_minimum) {
  35. for(const auto& element : row)
  36. cout << element << ' ';
  37. cout << '\n';
  38. }
  39. }
  40.  
Success #stdin #stdout 0s 3236KB
stdin
0 0 0 0 0 
0 1 1 0 1
0 1 0 0 1
0 0 0 0 0
0 1 1 1 0
stdout
5 4 3 2 1 
1 0 0 1 0 
1 0 2 1 0 
5 4 3 2 1 
1 0 0 0 1