wheelsmanx

AOC 2017 DAY1 source.cpp

Dec 5th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include "Header.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. vector<string> getInput() {
  7. vector<string> returnObject;
  8. returnObject = getInputFile("./Text.txt");
  9. return returnObject;
  10. }
  11.  
  12. vector<string> splitString(string input) {
  13. vector<string> returnObject;
  14. for (int i = 0; i < input.length(); i++) {
  15. string temp = char2String(input[i]);
  16. returnObject.push_back(temp);
  17. }
  18. return returnObject;
  19. }
  20.  
  21. vector<int> convert2Int(vector<string> input) {
  22. vector<int> returnObject;
  23. for (int i = 0; i < input.size(); i++) {
  24. returnObject.push_back(String2IntSingle(input[i]));
  25. }
  26. return returnObject;
  27. }
  28.  
  29. int answer(vector<int> input) {
  30. int returnObject = 0;
  31. int current;
  32. int next;
  33. for (int i = 0; i < input.size() - 1; i++) {
  34. current = input[i];
  35. next = input[i + 1];
  36. if (current == next) {
  37. returnObject = returnObject + (current);
  38. }
  39. }
  40. if (input[input.size() - 1] == input[0]) {
  41. returnObject = returnObject + input[input.size() - 1];
  42. }
  43. return returnObject;
  44. };
  45. void main() {
  46. vector<string> temp;
  47. temp = getInput();
  48. cout << answer(convert2Int(splitString(temp[0]))) << endl;
  49.  
  50. system("pause");
  51. }
Advertisement
Add Comment
Please, Sign In to add comment