Click here to Skip to main content
15,913,090 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralWelcome Pin
Code-o-mat5-May-12 23:11
Code-o-mat5-May-12 23:11 
Question64 bit problem Pin
appollosputnik4-May-12 4:41
appollosputnik4-May-12 4:41 
AnswerRe: 64 bit problem Pin
Albert Holguin4-May-12 9:58
professionalAlbert Holguin4-May-12 9:58 
AnswerRe: 64 bit problem Pin
«_Superman_»4-May-12 16:43
professional«_Superman_»4-May-12 16:43 
QuestionHelp for algorithm Pin
Falconapollo3-May-12 23:53
Falconapollo3-May-12 23:53 
QuestionRe: Help for algorithm Pin
Maximilien4-May-12 2:38
Maximilien4-May-12 2:38 
AnswerRe: Help for algorithm Pin
«_Superman_»4-May-12 3:15
professional«_Superman_»4-May-12 3:15 
GeneralRe: Help for algorithm Pin
Falconapollo5-May-12 20:12
Falconapollo5-May-12 20:12 
Thank you for your reply.

Your algorithm is great!

I made some modifications, so that it's perfect now!
C++
typedef vector<pair<char, char> > _OWN_TYPE;
_OWN_TYPE vecKey2Name;
bool GetSecond(const char& first, char& second)
{
	for (int i = 0; i < vecKey2Name.size(); ++i)
	{
		if(vecKey2Name[i].first == vecKey2Name[i].second)
			continue;
		if (first == (vecKey2Name[i].first))
		{
			second = vecKey2Name[i].second;
			return true;
		}
	}

	return false;
}

void GetDest(const char& src, char& dest)
{
	char src2 = src;

	while (GetSecond(src2, dest))
	{
		if (src == (dest))
			break;

		src2 = dest;
	}
}

int main()
{
	vecKey2Name.push_back(make_pair('X', 'Y'));
	vecKey2Name.push_back(make_pair('A', 'B'));
	vecKey2Name.push_back(make_pair('C', 'D'));
	vecKey2Name.push_back(make_pair('B', 'C'));
	vecKey2Name.push_back(make_pair('T', 'X'));
	vecKey2Name.push_back(make_pair('Y', 'T'));

	for(_OWN_TYPE::iterator itr = vecKey2Name.begin(); itr != vecKey2Name.end(); ++itr)
		cout << (itr->first) << " --> " << (itr->second) << endl;

	for(_OWN_TYPE::iterator itr = vecKey2Name.begin(); itr != vecKey2Name.end(); ++itr)
		GetDest(itr->first, itr->second);

	cout << "=============================================================" << endl;
	for(_OWN_TYPE::iterator itr = vecKey2Name.begin(); itr != vecKey2Name.end(); ++itr)
		cout << itr->first << " --> " << itr->second << endl;
}


modified 6-May-12 6:25am.

AnswerRe: Help for algorithm Pin
Albert Holguin4-May-12 10:12
professionalAlbert Holguin4-May-12 10:12 
GeneralRe: Help for algorithm Pin
Falconapollo5-May-12 20:29
Falconapollo5-May-12 20:29 
QuestionRe: Help for algorithm Pin
CPallini4-May-12 10:47
mveCPallini4-May-12 10:47 
AnswerRe: Help for algorithm Pin
Falconapollo5-May-12 20:37
Falconapollo5-May-12 20:37 
QuestionRe: Help for algorithm Pin
CPallini6-May-12 22:42
mveCPallini6-May-12 22:42 
AnswerRe: Help for algorithm Pin
Falconapollo8-May-12 19:30
Falconapollo8-May-12 19:30 
AnswerRe: Help for algorithm Pin
Philippe Mori5-May-12 1:55
Philippe Mori5-May-12 1:55 
GeneralRe: Help for algorithm Pin
Falconapollo5-May-12 20:41
Falconapollo5-May-12 20:41 
GeneralRe: Help for algorithm Pin
Philippe Mori6-May-12 2:12
Philippe Mori6-May-12 2:12 
QuestionSOLVED Project cannot be build. Two cpp files configured to produce pch error. Pin
Vaclav_3-May-12 4:45
Vaclav_3-May-12 4:45 
AnswerRe: Project cannot be build. Two cpp files configured to produce pch error. Pin
Richard MacCutchan3-May-12 6:47
mveRichard MacCutchan3-May-12 6:47 
GeneralRe: Project cannot be build. Two cpp files configured to produce pch error. Pin
Vaclav_3-May-12 8:02
Vaclav_3-May-12 8:02 
GeneralRe: Project cannot be build. Two cpp files configured to produce pch error. Pin
Richard MacCutchan3-May-12 8:10
mveRichard MacCutchan3-May-12 8:10 
GeneralRe: Project cannot be build. Two cpp files configured to produce pch error. Pin
Vaclav_3-May-12 8:36
Vaclav_3-May-12 8:36 
GeneralRe: Project cannot be build. Two cpp files configured to produce pch error. Pin
Vaclav_3-May-12 8:58
Vaclav_3-May-12 8:58 
GeneralRe: Project cannot be build. Two cpp files configured to produce pch error. Pin
Richard MacCutchan3-May-12 9:55
mveRichard MacCutchan3-May-12 9:55 
QuestionHow to change the path were files are created Pin
dliviu3-May-12 0:04
dliviu3-May-12 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.