SHARE
TWEET

Untitled

a guest Dec 7th, 2019 212 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Day_1.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms.
  2. //
  3.  
  4. #include "../includes/aoc.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. #include <sstream>
  9. #include <map>
  10.  
  11. std::string getPixel(std::vector<std::string>& inputs, int index)
  12. {
  13.     for (int i = 0; i < inputs.size(); ++i)
  14.     {
  15.         if (inputs[i].at(index) != '2')
  16.         {
  17.             return inputs[i].substr(index, 1);
  18.         }
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     util::Timer myTime;
  25.     myTime.start();
  26.     const int height = 6;
  27.     const int width = 25;
  28.     std::string inputString = util::readFile("..\\inputs\\input_2019_8.txt");
  29.  
  30.     std::vector<std::string> images;
  31.     for (int index = 0; index < inputString.length(); index += height * width)
  32.     {
  33.         images.push_back(inputString.substr(index, height * width));
  34.     }
  35.  
  36.     if (images.back() == "\n")
  37.         images.pop_back();
  38.  
  39.     std::vector<int> countZero;
  40.     std::vector<int> countOne;
  41.     std::vector<int> countTwo;
  42.     for (int index = 0; index < images.size(); ++index)
  43.     {
  44.         countZero.push_back(std::count(images[index].begin(), images[index].end(), '0'));
  45.         countOne.push_back(std::count(images[index].begin(), images[index].end(), '1'));
  46.         countTwo.push_back(std::count(images[index].begin(), images[index].end(), '2'));
  47.     }
  48.  
  49.     int minVal = 10000;
  50.     int result = 0;
  51.     for (int index = 0; index < images.size(); ++index)
  52.     {
  53.         if (countZero[index] < minVal)
  54.         {
  55.             minVal = countZero[index];
  56.             result = countOne[index] * countTwo[index];
  57.         }
  58.     }
  59.  
  60.     std::string resultString = "";
  61.  
  62.     for (int i = 0; i < height * width; ++i)
  63.     {
  64.         resultString += getPixel(images, i);
  65.     }
  66.  
  67.     std::cout << "Part 1: " << result << std::endl;
  68.     std::cout << "Part 2: " << resultString << std::endl;
  69.  
  70.     std::cout << "Time taken: " << myTime.msPassed() << " [ms]" << std::endl;
  71.     getchar();
  72.     return 0;
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top