Created
May 15, 2017 10:42
-
-
Save jason790228/1421fdd0d7749b2385e39d62f49ad9d4 to your computer and use it in GitHub Desktop.
11764
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "stdafx.h" | |
#include <gtest\gtest.h> | |
#include "C11764.h" | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
C11764 c11764; | |
c11764.Input(); | |
c11764.Run(); | |
testing::InitGoogleTest(&argc, argv); | |
RUN_ALL_TESTS(); | |
system("pause"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include "C11764.h" | |
#include <iostream> | |
using namespace std; | |
void C11764::Input() | |
{ | |
stringstream ss; | |
string sTestNumber; | |
int iTestNumber; | |
cin >> sTestNumber; | |
ss << sTestNumber; | |
ss >> iTestNumber; | |
for (int i = 0; i < iTestNumber; i++) | |
{ | |
string sWallNumber; | |
int iWallNumber; | |
cin >> sWallNumber; | |
ss << sWallNumber; | |
ss >> iWallNumber; | |
cin.ignore(1024, '\n'); | |
string temp; | |
getline(cin, temp); | |
m_input.push_back(temp); | |
} | |
} | |
void C11764::Run() | |
{ | |
for (int i = 0; i < m_input.size(); i++) | |
cout << "Case " << i + 1 << ": " << JumpScoreComputer(m_input[i], HIGHJUMP) << " " << JumpScoreComputer(m_input[i], LOWJUMP) << endl; | |
} | |
int C11764::JumpScoreComputer(const string &wall, JumpScoreType jumpScoreType) | |
{ | |
vector<int> wallList = WallStringParser(wall, " "); | |
return JumpScoreComputerImp(wallList, jumpScoreType); | |
} | |
vector<int> C11764::WallStringParser(const string wall, const string& delim) | |
{ | |
vector<int> wallList; | |
stringstream ss; | |
char *pch = strtok((char*)wall.c_str(), delim.c_str()); | |
while (pch != NULL) | |
{ | |
int temp; | |
ss.clear(); | |
ss << pch; | |
ss >> temp; | |
wallList.push_back(temp); | |
pch = strtok(NULL, delim.c_str()); | |
} | |
return wallList; | |
} | |
int C11764::JumpScoreComputerImp(vector<int> wallList, JumpScoreType jumpScoreType) | |
{ | |
int score(0); | |
switch (jumpScoreType) | |
{ | |
case HIGHJUMP: | |
for (int i = 0; i < wallList.size() - 1; i++) | |
(wallList[i] < wallList[i + 1]) ? score++ : score; | |
break; | |
case LOWJUMP: | |
for (int i = 0; i < wallList.size() - 1; i++) | |
(wallList[i] > wallList[i + 1]) ? score++ : score; | |
break; | |
default: | |
break; | |
} | |
return score; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class C11764 | |
{ | |
public: | |
enum JumpScoreType | |
{ | |
HIGHJUMP, | |
LOWJUMP | |
}; | |
public: | |
C11764(){ } | |
~C11764(){ } | |
void Input(); | |
void Run(); | |
//private: | |
vector<int> WallStringParser(const string wall, const string& delim); | |
int JumpScoreComputer(const string &wall, JumpScoreType jumpScoreType); | |
int JumpScoreComputerImp(vector<int> wallList, JumpScoreType jumpScoreType); | |
private: | |
vector<string> m_input; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#pragma once | |
#include <gtest\gtest.h> | |
#include "C11764.h" | |
struct test11764 : testing::Test | |
{ | |
C11764* c11764; | |
test11764() | |
{ | |
c11764 = new C11764(); | |
} | |
virtual ~test11764() | |
{ | |
c11764->~C11764(); | |
} | |
}; | |
TEST(HighJumpScore, HighJumpScore) | |
{ | |
C11764 c11764; | |
EXPECT_EQ(1, c11764.JumpScoreComputer("1 5", C11764::JumpScoreType::HIGHJUMP)); | |
EXPECT_EQ(0, c11764.JumpScoreComputer("5 1", C11764::JumpScoreType::HIGHJUMP)); | |
EXPECT_EQ(0, c11764.JumpScoreComputer("5 5", C11764::JumpScoreType::HIGHJUMP)); | |
} | |
TEST(LowJumpScore, LowJumpScore) | |
{ | |
C11764 c11764; | |
EXPECT_EQ(0, c11764.JumpScoreComputer("1 5", C11764::JumpScoreType::LOWJUMP)); | |
EXPECT_EQ(1, c11764.JumpScoreComputer("5 1", C11764::JumpScoreType::LOWJUMP)); | |
EXPECT_EQ(0, c11764.JumpScoreComputer("5 5", C11764::JumpScoreType::LOWJUMP)); | |
} | |
TEST(HighJumpScores, HighJumpScores) | |
{ | |
C11764 c11764; | |
EXPECT_EQ(4, c11764.JumpScoreComputer("1 4 2 2 3 5 3 4", C11764::JumpScoreType::HIGHJUMP)); | |
EXPECT_EQ(1, c11764.JumpScoreComputer("5 1 5", C11764::JumpScoreType::HIGHJUMP)); | |
EXPECT_EQ(0, c11764.JumpScoreComputer("5 5 5", C11764::JumpScoreType::HIGHJUMP)); | |
} | |
TEST(LowJumpScores, LowJumpScores) | |
{ | |
C11764 c11764; | |
EXPECT_EQ(2, c11764.JumpScoreComputer("1 4 2 2 3 5 3 4", C11764::JumpScoreType::LOWJUMP)); | |
EXPECT_EQ(1, c11764.JumpScoreComputer("5 1 5", C11764::JumpScoreType::HIGHJUMP)); | |
EXPECT_EQ(0, c11764.JumpScoreComputer("5 5 5", C11764::JumpScoreType::HIGHJUMP)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment