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