Zanaran

Untitled

Mar 5th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <random>
  6.  
  7. int main()
  8. {
  9. std::fstream inf("test.d",std::ios::in); //Create file streams
  10. std::ofstream outf("test.dlvl",std::ios::out);
  11.  
  12. unsigned int coln = 10; //Max columns
  13. unsigned int rown = 9; //Max rows
  14. int y = 0; //Current row
  15. int x = 0; //Current column
  16.  
  17. std::vector< std::vector<int> > v; //Initialize 2D vector
  18.  
  19. v.resize(coln, std::vector<int>(rown, 0)); //Expand it to the max columns and rows
  20.  
  21. //READING INPUT
  22. while(!((y == rown) && (x == coln))) //while the max boundaries haven't been reached
  23. {
  24. if (!(inf.eof())) //when the file hasn't ended
  25. {
  26. inf >> v[x][y]; //put file info inside of the vector
  27. }
  28. else
  29. {
  30. v[x][y] = 0; //otherwise fill the blank spaces with 0
  31. }
  32.  
  33. x++;
  34. if ((y == rown) && (x == coln)) break; //once the max boundaries have been reached, exit
  35. if (x == coln) //new line
  36. {
  37. x = 0; //resets the column position, and
  38. y++; //moves the row position down one line
  39. }
  40. }
  41. y = 0; //reset
  42. x = 0;
  43.  
  44. //WRITING THE OUTPUT
  45. while (true)
  46. {
  47. int r = 0; //I need this because...
  48. r = v[x][y]; //...I have to use the value from the vector...
  49. switch (r) ///...in a switch statement
  50. {
  51. case 0:
  52. {
  53. outf << '!';
  54. }
  55. break;
  56. case 1:
  57. {
  58. outf << '@';
  59. }
  60. break;
  61. case 2:
  62. {
  63. outf << '#';
  64. }
  65. break;
  66. case 3:
  67. {
  68. outf << '$';
  69. }
  70. break;
  71. case 4:
  72. {
  73. outf << '%';
  74. }
  75. }
  76. outf << ' '; //whitespace for readability
  77. x++;
  78. if (((y == rown) && (x == coln))) break;
  79. if (x == coln)
  80. {
  81. x = 0;
  82. y++;
  83. outf << std::endl;
  84. }
  85. }
  86. system("PAUSE");
  87. inf.close();
  88. outf.close();
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment