Click here to Skip to main content
15,911,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Eliminating Flickering when resizing a window Pin
Member 148659428-Dec-04 7:26
Member 148659428-Dec-04 7:26 
GeneralAuto-scroll a CDialog Pin
DanYELL28-Dec-04 6:00
DanYELL28-Dec-04 6:00 
GeneralRe: Auto-scroll a CDialog Pin
Gary R. Wheeler29-Dec-04 1:32
Gary R. Wheeler29-Dec-04 1:32 
GeneralUsing MapPoint classes generated from Type Library Pin
BlackDice28-Dec-04 4:55
BlackDice28-Dec-04 4:55 
GeneralCode-a-phone Pin
David Crow28-Dec-04 4:18
David Crow28-Dec-04 4:18 
GeneralRe: Code-a-phone Pin
Tom Wright29-Dec-04 4:19
Tom Wright29-Dec-04 4:19 
GeneralRe: Code-a-phone Pin
David Crow29-Dec-04 4:45
David Crow29-Dec-04 4:45 
Questionwhat is the error in the following code? (not giving the required output). Pin
babur khan28-Dec-04 3:38
babur khan28-Dec-04 3:38 
This program in g++ under liunux. then i made it to compile it under vc++(of course i have to change things slightly). the program is compiling without any error but it is not giving any output.


This code is compiled under VC++:

#include <iostream>
#include <set>
#include <queue>
#include <list>

using namespace std;

#include <stdio.h> // 2

struct Situation {
set<int> left, right;
bool torchLeft;
int minutesPassed;
list<string> description;
};

bool operator<(const Situation &a, const Situation &b)
{
return a.minutesPassed > b.minutesPassed;
}

int main()
{
const char *n[11] = { 0, "A", "B", 0, 0, "C", 0, 0, 0, 0, "D" };
priority_queue<Situation> q;
Situation s;
char d[256];

// initial situation: all persons and torch on the left
s.left.insert(1);
s.left.insert(2);
s.left.insert(5);
s.left.insert(10);
s.torchLeft = true;
s.minutesPassed = 0;
q.push(s);

while (!q.empty()) {

// q is sorted by minutesPassed increasing, get the top-most
// entry, which has the shortest minutesPassed of the queue
s = q.top();
q.pop();

// if all persons are on the right, this is a solution
if (s.left.empty()) {
cout << "solution found: " << s.minutesPassed <<
" minutes" << endl;
for (list<string>::iterator i = s.description.begin();
i != s.description.end(); ++i)
cout << " " << (*i).c_str << endl; // 1
cout << endl;
continue;
}

set<int> &src = s.torchLeft ? s.left : s.right;

// single person moving
for (set<int>::iterator i = src.begin(); i != src.end(); ++i) {
Situation t = s;
if (t.torchLeft) {
t.left.erase(*i);
t.right.insert(*i);
} else {
t.right.erase(*i);
t.left.insert(*i);
}
t.minutesPassed += *i;
if (t.minutesPassed >= 18)
continue;
_snprintf(d, sizeof(d), "%s moves %s (%d minutes, %d " // 2
"total)", n[*i], t.torchLeft ? "across" : "back",
*i, t.minutesPassed);
t.description.insert(t.description.end(), d);
t.torchLeft = !t.torchLeft;
q.push(t);
}

// two persons moving
{ // 3
for (set<int>::iterator i = src.begin(); i != src.end(); ++i)
for (set<int>::iterator j = i; j != src.end(); ++j) {
if (j == i)
continue;
Situation t = s;
if (t.torchLeft) {
t.left.erase(*i);
t.left.erase(*j);
t.right.insert(*i);
t.right.insert(*j);
} else {
t.right.erase(*i);
t.right.erase(*j);
t.left.insert(*i);
t.left.insert(*j);
}
t.minutesPassed += *i > *j ? *i : *j;
if (t.minutesPassed >= 18)
continue;
_snprintf(d, sizeof(d), "%s and %s move %s (%d " // 2
"minutes, %d total)", n[*i], n[*j],
t.torchLeft ? "across" : "back",
*i > *j ? *i : *j, t.minutesPassed);
t.description.insert(t.description.end(), d);
t.torchLeft = !t.torchLeft;
q.push(t);
}
}
}

return 0;
}

the required output should be like this:
solution found: 17 minutes
A and B move across (2 minutes, 2 total)
A moves back (1 minutes, 3 total)
C and D move across (10 minutes, 13 total)
B moves back (2 minutes, 15 total)
A and B move across (2 minutes, 17 total)

solution found: 17 minutes
A and B move across (2 minutes, 2 total)
B moves back (2 minutes, 4 total)
C and D move across (10 minutes, 14 total)
A moves back (1 minutes, 15 total)
A and B move across (2 minutes, 17 total)


can you please point out the error and re-paste the correct code(so that i can compare and understand better), i will be thankful to you.




AnswerRe: what is the error in the following code? (not giving the required output). Pin
El Corazon28-Dec-04 4:15
El Corazon28-Dec-04 4:15 
GeneralRe: what is the error in the following code? (not giving the required output). Pin
Neville Franks28-Dec-04 9:09
Neville Franks28-Dec-04 9:09 
GeneralFinding type size Pin
Franz Klein28-Dec-04 2:21
Franz Klein28-Dec-04 2:21 
GeneralRe: Finding type size Pin
Chris Losinger28-Dec-04 3:08
professionalChris Losinger28-Dec-04 3:08 
GeneralRe: Finding type size Pin
Gary R. Wheeler28-Dec-04 4:35
Gary R. Wheeler28-Dec-04 4:35 
GeneralNewest file on ftp Pin
Dariusz M. Mikulski28-Dec-04 1:39
Dariusz M. Mikulski28-Dec-04 1:39 
GeneralProgress Bar in StatusBar Pin
Neelesh K J Jain28-Dec-04 1:04
Neelesh K J Jain28-Dec-04 1:04 
GeneralHide Internet Explorer Menu Bars and Toolbars Pin
Member 24341328-Dec-04 0:28
Member 24341328-Dec-04 0:28 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
gsaigopal28-Dec-04 0:31
sussgsaigopal28-Dec-04 0:31 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
Member 24341328-Dec-04 16:04
Member 24341328-Dec-04 16:04 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
Alok Bhardwaj29-Dec-04 19:16
Alok Bhardwaj29-Dec-04 19:16 
GeneralRe: Hide Internet Explorer Menu Bars and Toolbars Pin
Alok Bhardwaj29-Dec-04 19:35
Alok Bhardwaj29-Dec-04 19:35 
QuestionHow to prevent from inhertance Pin
Kiran Kumar Singani28-Dec-04 0:26
Kiran Kumar Singani28-Dec-04 0:26 
AnswerRe: How to prevent from inhertance Pin
Prakash Nadar28-Dec-04 0:34
Prakash Nadar28-Dec-04 0:34 
GeneralRe: How to prevent from inhertance Pin
virtualkirankumar28-Dec-04 0:40
virtualkirankumar28-Dec-04 0:40 
GeneralRe: How to prevent from inhertance Pin
Prakash Nadar28-Dec-04 0:46
Prakash Nadar28-Dec-04 0:46 
AnswerRe: How to prevent from inhertance Pin
jan larsen28-Dec-04 1:39
jan larsen28-Dec-04 1:39 

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.