Y字路巡り


```Source.cpp
#include "Header.h"

struct PlaceList{
	std::string nowPlace;
	std::string oldPlace;
	std::string leftPlace;
	std::string rightPlace;
};

PlaceList placeList[PLACEPATERN] = {
	{"A","B","D","C",},
	{"B","C","E","A",},
	{"C","A","F","B",},
	{"A","C","B","D",},
	{"C","B","A","F",},
	{"B","A","C","E",},

	{"A","D","C","B",},
	{"B","E","A","C",},
	{"C","F","B","A",},
	{"D","A","E","F",},
	{"E","B","F","D",},
	{"F","C","D","E",},

	{"D","E","F","A",},
	{"E","F","D","B",},
	{"F","D","E","C",},
	{"D","F","A","E",},
	{"F","E","C","D",},
	{"E","D","B","F",},
};

void Yjiro::initPlaceInfo()
{
	m_nowPlace = "A";
	m_oldPlace = "B";
}

void Yjiro::moveBack()
{
	std::swap(m_oldPlace, m_nowPlace);
}

void Yjiro::moveLeft(const unsigned int& placeInfoNumber)
{
	m_oldPlace = m_nowPlace;
	m_nowPlace = placeList[placeInfoNumber].leftPlace;
}

void Yjiro::moveRight(const unsigned int& placeInfoNumber)
{
	m_oldPlace = m_nowPlace;
	m_nowPlace = placeList[placeInfoNumber].rightPlace;
}

const unsigned int Yjiro::getPlaceInfoNumber()
{
	for(int i=0; i<PLACEPATERN; i++){
		if((placeList[i].nowPlace == m_nowPlace) && placeList[i].oldPlace == m_oldPlace)
			return i;
	}
}

void Yjiro::move(const char& input)
{
	if(input == 'b'){
		moveBack();
		return;
	}
	const unsigned int placeInfoNumber = getPlaceInfoNumber();
	input == 'r' ? moveRight(placeInfoNumber) : moveLeft(placeInfoNumber);
}

const std::string Yjiro::solve(const std::string& input)
{
	initPlaceInfo();
	std::string result = m_nowPlace;
	for(int i=0; i<input.size(); i++){
		move(input.at(i));
		result += m_nowPlace; 
	}
	return result;
}

void Yjiro::test(const std::string& input, const std::string& output)
{
	std::string result = solve(input);
	std::cout << output << ":" << result << std::endl;
	if(result == output){
		std::cout << "test is OK!" << std::endl;
	}else{
		std::cout << "test is NG!" << std::endl;
	}
}

int main()
{
	Yjiro yjiro;
	yjiro.test("b", "AB");
	yjiro.test("l", "AD");
	yjiro.test("r", "AC");
	yjiro.test("bbb", "ABAB");
	yjiro.test("rrr", "ACBA");
	yjiro.test("blll", "ABCAB");
	yjiro.test("llll", "ADEBA");
	yjiro.test("rbrl", "ACADE");
	yjiro.test("brrrr", "ABEDAB");
	yjiro.test("llrrr", "ADEFDE");
	yjiro.test("lrlll", "ADFEDF");
	yjiro.test("lrrrr", "ADFCAD");
	yjiro.test("rllll", "ACFDAC");
	yjiro.test("blrrrr", "ABCFEBC");
	yjiro.test("brllll", "ABEFCBE");
	yjiro.test("bbrllrrr", "ABACFDEFD");
	yjiro.test("rrrrblll", "ACBACABCA");
	yjiro.test("llrlrrbrb", "ADEFCADABA");
	yjiro.test("rrrbrllrr", "ACBABEFCAD");
	yjiro.test("llrllblrll", "ADEFCBCADEB");
	yjiro.test("lrrlllrbrl", "ADFCBEFDFCB");
	yjiro.test("lllrbrrlbrl", "ADEBCBACFCAB");
	yjiro.test("rrrrrrlrbrl", "ACBACBADFDEB");
	yjiro.test("lbrbbrbrbbrr", "ADABABEBCBCFE");
	yjiro.test("rrrrlbrblllr", "ACBACFCACFDAB");
	yjiro.test("lbbrblrlrlbll", "ADADFDABCFDFED");
	yjiro.test("rrbbrlrlrblrl", "ACBCBADFEBEFDA");
	yjiro.test("blrllblbrrrrll", "ABCFDADEDABEDFE");
	yjiro.test("blrllrlbllrrbr", "ABCFDABCBEFDEDA");
	yjiro.test("lbrbbrllllrblrr", "ADABABEFCBEDEBCF");
	yjiro.test("rrrrbllrlrbrbrr", "ACBACABCFDEDADFC");
	return 0;
}

```

```Header.h
#ifndef _HEADER_H
#define _HEADER_H

#include <string>
#include <iostream>

#define PLACEPATERN 18

class Yjiro
{
public:
	void test(const std::string& input, const std::string& output);
private:
	const std::string solve(const std::string& input);
	void initPlaceInfo();
	const unsigned int getPlaceInfoNumber();
	void move(const char& input);
	void moveBack();
	void moveLeft(const unsigned int& placeInfoNumber);
	void moveRight(const unsigned int& placeInfoNumber);
	std::string m_nowPlace;
	std::string m_oldPlace;
};

#endif
```