Advertisement
wheelsmanx

AOC DAY 3 PART 2 Source.cpp

May 15th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <iostream>
  2. #include "Header.h"
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int isTriPos(int A, int B, int C) {
  9. int returnObject = 0;
  10. if ((A + B) > C && (A + C) > B && (C + B) > A) {
  11. returnObject = 1;
  12. }
  13. else {
  14. returnObject = 0;
  15. }
  16. return returnObject;
  17. }
  18.  
  19. class triangle {
  20. public:
  21. int A, B, C, D, E, F, G, H, I;
  22. int isTri1;
  23. int isTri2;
  24. int isTri3;
  25. triangle(int a,int b, int c, int d, int e, int f, int g, int h , int i) {
  26. this->A = a;
  27. this->B = b;
  28. this->C = c;
  29. this->D = d;
  30. this->E = e;
  31. this->F = f;
  32. this->G = g;
  33. this->H = h;
  34. this->I = i;
  35. this->isTri1 = isTriPos(A, D, G);
  36. this->isTri2 = isTriPos(B, E, H);
  37. this->isTri3 = isTriPos(C, F, I);
  38. }
  39. };
  40.  
  41. int counter = 0;
  42.  
  43. void main() {
  44. vector <string> userInput = getInputFile("C:\\temp\\Tri.txt");
  45. vector <triangle> triList;
  46. vector <int> numbersData;
  47. for (int i = 0; i < userInput.size(); i++) {
  48. vector <string> userInputSplit = cstringsplit(userInput.at(i), " ");
  49. for (int b = 0; b < userInputSplit.size(); b++) {
  50. int tempInt = String2Int(userInputSplit.at(b));
  51. if (tempInt > 0) {
  52. numbersData.push_back(tempInt);
  53. }
  54. }
  55. }
  56. for (int i = 0; i < numbersData.size(); i = i + 9) {
  57. triangle temp(numbersData.at(i), numbersData.at(i + 1), numbersData.at(i + 2), numbersData.at(i + 3), numbersData.at(i + 4), numbersData.at(i + 5), numbersData.at(i + 6), numbersData.at(i + 7), numbersData.at(i + 8));
  58. triList.push_back(temp);
  59. }
  60. for (int i = 0; i < triList.size(); i++) {
  61. triangle triPtr = triList.at(i);
  62. if (triPtr.isTri1 == 1) {
  63. counter++;
  64. }
  65. if (triPtr.isTri2 == 1) {
  66. counter++;
  67. }
  68. if (triPtr.isTri3 == 1) {
  69. counter++;
  70. }
  71. }
  72. cout << counter << endl;
  73. system("pause");
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement