Advertisement
huutho_96

Tạo chuỗi

May 4th, 2016
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include "graphics.h"
  2.  
  3. #define X 640
  4. #define Y 320
  5.  
  6. #define ScreenW 160
  7.  
  8. int main( )
  9. {
  10.     system("MODE 160, 300");
  11.     initwindow(X, Y, "First Sample");
  12.     readimagefile("world-map.bmp", 0, 0, X - 1, Y - 1);
  13.  
  14.     float x, y;
  15.     x = X / ScreenW;
  16.     y = x / 0.75f;
  17.  
  18.     char str[1024] = "";
  19.     int h = 0;      //bien chay
  20.     int temp1 = 0;  //bien dem so '!' lien tiep
  21.     int temp2 = 0;  //bien dem so ' ' lien tiep
  22.  
  23.     for (int i = 1; i < Y; i += y)
  24.     {
  25.         for (int j = 1; j < X; j += x)
  26.         {
  27.             if (getpixel(j, i) != WHITE)
  28.             {
  29.                 if (temp2 != 0)
  30.                 {
  31.                     str[h++] = 64 + temp2;
  32.                     temp2 = 0;
  33.                 }
  34.                 temp1++;
  35.                 putchar('!');
  36.             }
  37.             else
  38.             {
  39.                 if (temp1 != 0)
  40.                 {
  41.                     str[h++] = 64 + temp1;
  42.                     temp1 = 0;
  43.                 }
  44.                 temp2++;
  45.                 putchar(' ');
  46.             }
  47.         }
  48.         if (temp1 != 0)
  49.             str[h++] = '1';
  50.         if (temp2 != 0)
  51.             str[h++] = '0';
  52.         temp1 = temp2 = 0;
  53.         putchar('\n');
  54.     }
  55.     getch();
  56.     str[h] = 0;
  57.     puts(str);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement