Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello Experts, Can someone please convert this c++ program to an identical c pro

ID: 3906699 • Letter: H

Question

Hello Experts,

Can someone please convert this c++ program to an identical c program? Thank you in advance.

----------------------------------------------------------------------------------------------------------------------

#include <map>
#include <string>
#include <cstdio>
#include <stack>
typedef std::pair<std::string, std::string> two_boxes;

int main(){
std::map<std::string, two_boxes> s_map;
std::map<std::string, bool> visited;
std::string firstLocation;
std::stack<std::string> boxes;
int numLocations;
  
scanf("%d", &numLocations);

for(int i = 0; i < numLocations; ++i){
char c1[20];
char c2[20];
char c3[20];
scanf("%s %s %s", c1, c2, c3);
s_map[c1] = two_boxes(c2, c3);
visited[c1] = false;
if(i == 0){
firstLocation = c1;
}
}
// this is not a real box
// it is only an auxiliar box to instruct
// stackula to go to the first location in the input.
boxes.push(firstLocation);

do{
std::string curLocation = boxes.top();
// when stackula shows up to a place
// patrons take the boxes from the top of Stackula's
// (if they are the recipants
do{
boxes.pop();
}while((!boxes.empty()) && (boxes.top() == curLocation));
// and immediately place both of their outgoing boxes
// on top of Stackula's stack
if(!visited[curLocation]){
boxes.push(s_map[curLocation].first);
boxes.push(s_map[curLocation].second);
visited[curLocation] = true;
}
// for the given delivery list output the list of cities
// in the order they will be visited.
printf("%s ", curLocation.c_str());
fflush(stdout);
}while(!boxes.empty());
return 0;
}

Explanation / Answer

#include <map.h>
#include <string.h>
#include <cstdio.h>
#include <stack.h>
#include<stdio.h>
typedef std::pair<std::string, std::string> two_boxes;

void main(){
std::map<std::string, two_boxes> s_map;
std::map<std::string, bool> visited;
std::string firstLocation;
std::stack<std::string> boxes;
int numLocations;
  
scanf("%d", &numLocations);

for(int i = 0; i < numLocations; ++i){
char c1[20];
char c2[20];
char c3[20];
scanf("%s %s %s", c1, c2, c3);
s_map[c1] = two_boxes(c2, c3);
visited[c1] = false;
if(i == 0){
firstLocation = c1;
}
}
// this is not a real box
// it is only an auxiliar box to instruct
// stackula to go to the first location in the input.
boxes.push(firstLocation);

do{
std::string curLocation = boxes.top();
// when stackula shows up to a place
// patrons take the boxes from the top of Stackula's
// (if they are the recipants
do{
boxes.pop();
}while((!boxes.empty()) && (boxes.top() == curLocation));
// and immediately place both of their outgoing boxes
// on top of Stackula's stack
if(!visited[curLocation]){
boxes.push(s_map[curLocation].first);
boxes.push(s_map[curLocation].second);
visited[curLocation] = true;
}
// for the given delivery list output the list of cities
// in the order they will be visited.
printf("%s ", curLocation.c_str());
fflush(stdout);
}while(!boxes.empty());

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote