Guest User

Untitled

a guest
Mar 5th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. int main()
  6. {
  7.     std::fstream inf("test.d", std::ios::in); //Create file streams
  8.     std::ofstream outf("test.dlvl", std::ios::out);
  9.  
  10.     unsigned int coln = 10; //Max columns
  11.     unsigned int rown = 9; //Max rows
  12.     int y = 0; //Current row
  13.     int x = 0; //Current column
  14.     char tileset[] = { '!', '@', '#', '$', '%' };
  15.  
  16.     std::vector< std::vector<int> > v; //Initialize 2D vector
  17.  
  18.     v.resize(coln, std::vector<int>(rown, 0)); //Expand it to the max columns and rows
  19.  
  20.     //READING INPUT
  21.     while (!(y == rown && x == coln)) //while the max boundaries haven't been reached
  22.     {
  23.         v[x++][y] = !inf.eof() ? inf.get() : 0;
  24.         if (y == rown && x == coln)
  25.             break; //once the max boundaries have been reached, exit
  26.         if (x == coln) //new line
  27.         {
  28.             x = 0; //resets the column position, and
  29.             y++; //moves the row position down one line
  30.         }
  31.     }
  32.     y = 0; //reset
  33.     x = 0;
  34.     inf.close();
  35.  
  36.     //WRITING THE OUTPUT
  37.     while (true)
  38.     {
  39.         outf << tileset[v[x++][y]] << ' '; //whitespace for readability
  40.         if ((y == rown && x == coln))
  41.             break;
  42.         if (x == coln)
  43.         {
  44.             x = 0;
  45.             y++;
  46.             outf << std::endl;
  47.         }
  48.     }
  49.     outf.close();
  50.  
  51.     return 0;
  52. }
Add Comment
Please, Sign In to add comment