Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <string>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. vector<int> solution(vector<int> answers) {
  9. vector<int> answer;
  10. pair<int, int> tmp;
  11. pair<int, int> myInfo[3] = {{1,0}, {2,0}, {3,0}};
  12. int problemSize = answers.size();
  13. int how_1[] = { 0,1,2,3,4,5 };
  14. int how_2[] = { 0,2,1,2,3,2,4,2,5 };
  15. int how_3[] = { 0,3,3,1,1,2,2,4,4,5,5 };
  16.  
  17. for (int i = 0; i<problemSize; i++) {
  18. if (i % 5 == 0) {
  19. idx_1 = 1;
  20. }
  21. if (i % 8 == 0) {
  22. idx_2 = 1;
  23. }
  24. if (i % 10 == 0) {
  25. idx_3 = 1;
  26. }
  27. if (how_1[idx_1] == answers[i]) {
  28. myInfo[0].second++;
  29. }
  30. if (how_2[idx_2] == answers[i]) {
  31. myInfo[1].second++;
  32. }
  33. if (how_3[idx_3] == answers[i]) {
  34. myInfo[2].second++;
  35. }
  36. idx_1++;
  37. idx_2++;
  38. idx_3++;
  39. }
  40. for(int i = 0; i< 2; i++){
  41. for(int j = 0; j<2-i; j++){
  42. if(myInfo[j].second < myInfo[j+1].second){
  43. tmp = myInfo[j];
  44. myInfo[j] = myInfo[j+1];
  45. myInfo[j+1] = tmp;
  46. }
  47. }
  48. }
  49.  
  50. answer.push_back(myInfo[0].first);
  51. if (myInfo[0].second == myInfo[1].second) {
  52. answer.push_back(myInfo[1].first);
  53. if (myInfo[1].second == myInfo[2].second)
  54. answer.push_back(myInfo[2].first);
  55. }
  56.  
  57. return answer;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement