fork download
  1. #include <cstddef>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. const std::size_t HEIGHT = 10;
  6. const std::size_t WIDTH = 10;
  7.  
  8. typedef std::vector<char> MatrixDim;
  9. typedef std::vector<MatrixDim> Matrix;
  10. typedef MatrixDim::size_type MatrixDimSize;
  11.  
  12. inline void set_bit(Matrix& matrix, MatrixDimSize x, MatrixDimSize y)
  13. {
  14. matrix[(x) / 8][y] |= (0x80 >> ((x) % 8));
  15. }
  16.  
  17. void print_screen(Matrix const& matrix)
  18. {
  19. for (MatrixDimSize y = 0; y < HEIGHT; y++)
  20. {
  21. for (MatrixDimSize x = 0; x < WIDTH/8+1; x++)
  22. {
  23. for (int i = 0x80; i != 0; i >>= 1)
  24. {
  25. std::cout << (((matrix[x][y] & i) != 0) ? '*' : ' ');
  26. }
  27. }
  28.  
  29. std::cout << "\n";
  30. }
  31. }
  32.  
  33. int main()
  34. {
  35. Matrix matrix(HEIGHT, MatrixDim(WIDTH));
  36.  
  37. for (MatrixDimSize x = 0; x < WIDTH; x++)
  38. {
  39. for (MatrixDimSize y = 0; y < HEIGHT; y++)
  40. {
  41. if (x == 0 || y == 0 || x == WIDTH-1 || y == HEIGHT-1)
  42. {
  43. set_bit(matrix, x, y);
  44. }
  45. }
  46. }
  47.  
  48. print_screen(matrix);
  49. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
**********      
*        *      
*        *      
*        *      
*        *      
*        *      
*        *      
*        *      
*        *      
**********