Skip to content

Instantly share code, notes, and snippets.

@jason790228
Created May 15, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jason790228/1421fdd0d7749b2385e39d62f49ad9d4 to your computer and use it in GitHub Desktop.
Save jason790228/1421fdd0d7749b2385e39d62f49ad9d4 to your computer and use it in GitHub Desktop.
11764
#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;
}
#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;
}
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;
};
#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