wheelsmanx

AOC 2017 DAY1 Header.h

Dec 5th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <stdlib.h>
  8. #include <map>
  9. #include <set>
  10.  
  11. using namespace std;
  12. /*
  13. vout(vector<string/int/char>);
  14. // just std::cout << string/int/char << endl;
  15. test();
  16. // this just std outputs "this is a test"
  17. getInputFile("locationoftextFile");
  18. // this returns vector of strings of text file
  19. String2Int(string);
  20. // converts string to int
  21. Int2String(int);
  22. //converts int to string
  23. cStringSplit(string input, string delimiter);
  24. // returns vector of strings separated by the delimiter
  25.  
  26. */
  27.  
  28.  
  29. vector<string> returnMapKeyString(map<string, string> userInput) {
  30. vector<string> returnObject;
  31. for (auto element : userInput) {
  32. returnObject.push_back(element.first);
  33. }
  34. return returnObject;
  35. }
  36. vector<string> returnMapValueString(map<string, string> userInput) {
  37. vector<string> returnObject;
  38. for (auto element : userInput) {
  39. returnObject.push_back(element.second);
  40. }
  41. return returnObject;
  42. }
  43.  
  44. vector<int> returnMapKeyInt(map<int, int> userInput) {
  45. vector<int> returnObject;
  46. for (auto element : userInput) {
  47. returnObject.push_back(element.first);
  48. }
  49. return returnObject;
  50. }
  51. vector<int> returnMapValueInt(map<int, int> userInput) {
  52. vector<int> returnObject;
  53. for (auto element : userInput) {
  54. returnObject.push_back(element.second);
  55. }
  56. return returnObject;
  57. }
  58.  
  59. void readStringMap(map<string, string> userInput) {
  60. cout << endl;
  61. for (auto element : userInput) {
  62. cout << element.first << " <= " << element.second << endl;
  63. }
  64. cout << endl;
  65. }
  66.  
  67. void readIntMap(map<int, int> userInput) {
  68. cout << endl;
  69. for (auto element : userInput) {
  70. cout << element.first << " <= " << element.second << endl;
  71. }
  72. cout << endl;
  73. }
  74.  
  75. vector <int> String2Int(vector <string> tempVector) {
  76. stringstream tempSS;
  77. vector <int> tempIntVector;
  78. int tempInt;
  79. for (int i = 0; i < tempVector.size(); i++) {
  80. tempSS << tempVector.at(i);
  81. tempSS >> tempInt;
  82. tempIntVector.push_back(tempInt);
  83. }
  84. return tempIntVector;
  85. }
  86.  
  87. string char2String(char input) {
  88. string returnObject;
  89. stringstream tempSS;
  90. tempSS << input;
  91. tempSS >> returnObject;
  92. return returnObject;
  93. }
  94.  
  95. int String2IntSingle(string userInput) {
  96. stringstream tempSS;
  97. int tempInt;
  98. tempSS << userInput;
  99. tempSS >> tempInt;
  100. return tempInt;
  101. }
  102.  
  103. vector <string> cStringSplit(string input, string delimeter) {
  104. int delimSize = delimeter.length();
  105. int inputSize = input.length();
  106. string buffer;
  107. vector <string> v;
  108. for (int i = 0; i < inputSize; i++) {
  109. if (input.substr(i, delimSize) != delimeter) {
  110. buffer += input[i];
  111. }
  112. else {
  113. v.push_back(buffer);
  114. buffer = "";
  115. i = i + delimSize - 1;
  116. }
  117. }
  118. v.push_back(buffer);
  119. buffer = "";
  120. return v;
  121. }
  122.  
  123. vector<string> getInputFile(string location) {
  124. // good example getFile("C:\\temp\\New Text Document.txt");
  125. ifstream fileInput;
  126. vector<string> tempVector;
  127. string tempString;
  128. fileInput.open(location);
  129. while (!fileInput.eof())
  130. {
  131. getline(fileInput, tempString);
  132. tempVector.push_back(tempString);
  133. tempString = " ";
  134. }
  135. return tempVector;
  136. }
  137. void test() {
  138. cout << "TEST" << endl;
  139. }
  140.  
  141. void vout(vector<string> temp) { for (string c : temp) { cout << c << endl; } }
  142. void vout(vector<int> temp) { for (int c : temp) { cout << c << endl; } }
  143. void vout(vector<bool> temp) { for (bool c : temp) { cout << c << endl; } }
  144. void vout(vector<char> temp) { for (char c : temp) { cout << c << endl; } }
Advertisement
Add Comment
Please, Sign In to add comment