fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. class matrix_t
  7. {
  8. size_t col_count, row_count;
  9. vector< bool > data;
  10.  
  11. size_t as_index( const size_t col, const size_t row ) const
  12. {
  13. return row * col_count + col;
  14. }
  15.  
  16. public:
  17.  
  18. matrix_t( const size_t col_count, const size_t row_count )
  19. : col_count( col_count )
  20. , row_count( row_count )
  21. , data( row_count*col_count )
  22. {
  23. // nop
  24. }
  25.  
  26. auto at( const size_t col, const size_t row ) const
  27. {
  28. return data[ as_index( col, row ) ];
  29. }
  30.  
  31. auto at( const size_t col, const size_t row )
  32. {
  33. return data[ as_index( col, row ) ];
  34. }
  35.  
  36. istream& read( istream& is )
  37. {
  38. for( size_t r = 0; r < row_count; ++r )
  39. {
  40. for( size_t c = 0; c < col_count; ++c )
  41. {
  42. char t;
  43. is >> t;
  44. at( c, r ) = t == '0' ? false : true;
  45. }
  46. }
  47. return is;
  48. }
  49.  
  50. ostream& write( ostream& os )
  51. {
  52. for( size_t r = 0; r < row_count; ++r )
  53. {
  54. for( size_t c = 0; c < col_count; ++c )
  55. {
  56. os << at( c, r ) ? '1' : '0';
  57. }
  58. os << endl;
  59. }
  60. return os;
  61. }
  62.  
  63. };
  64.  
  65. int main()
  66. {
  67. size_t col, row;
  68. cin >> col >> row;
  69.  
  70. matrix_t m( col, row );
  71. m.read( cin );
  72.  
  73. cout << endl;
  74. m.write( cout );
  75.  
  76. return 0;
  77. }
  78.  
  79.  
Success #stdin #stdout 0s 15240KB
stdin
3 2
000
010
stdout
000
010