SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
NEED TO FIX ERRORS ONLY AND SHOW CODE WORKING. PLEASE USE MY
CODE AND ADD INPUT OUTPUT FILES. IN A HURRY WILL UPVOTE
NEED TO ADD THESE TWO FILES BUT KEPT GETTING ERRORS
input.txt:
162
10 139 138 4 28 117 63 31 48 74 11 49 118 52 128 153 130 47 17 95 110 18
70 24 112 26 64 115 141 30 87 8 46 34 80 36 13 38 39 102 61 76 120 23 156
106 116 68 85 147 59 121 78 37 53 50 54 91 101 60 94 22 107 71 123 6 67
103 145 152 75 134 73 108 25 140 77 104 127 20 81 2 154 96 151 86 135 88
89 90 58 1 93 161 29 35 97 56 79 82 124 19 7 142 21 143 100 129 109 146
111 5 98 55 45 133 43 16 148 92 113 42 65 83 125 126 114 51 3 62 144 157
150 57 40 136 137 159 162 131 119 69 44 99 158 14 33 9 149 105 15 32 41 12
155 122 132 84 66 72 160 27
1 2 6 5 9 8 7 4 3 12 11 13 10 17 18 20 22 21 25 31 30 32 33 29 34 35 28 41
40 42 39 43 38 46 47 48 51 50 49 45 52 44 56 55 54 53 37 57 36 58 59 60 27
26 61 62 24 23 19 16 65 66 64 67 68 63 15 75 74 73 72 76 77 79 80 82 83 81
85 88 87 94 93 95 92 96 97 91 90 99 102 101 104 105 103 107 111 110 109
108 106 100 112 98 89 114 117 116 118 115 113 119 121 120 123 122 124 126
127 128 130 129 125 131 132 135 136 139 138 140 137 134 133 142 145 148
149 147 153 155 154 152 151 156 150 146 144 160 159 158 157 161 143 141 86
84 78 71 70 69 14 162
144 44 136 40 128 141 8 115 125 131 58 55 145 14 64 28 19 59 76 48 25 16
20 27 7 143 63 112 17 30 65 34 39 130 117 67 82 120 85 154 107 42 151 99
96 46 47 159 162 22 66 12 53 157 113 38 97 11 29 18 10 24 60 75 4 132 90
122 56 79 119 72 150 80 103 35 106 102 15 54 69 6 62 105 5 84 87 88 89 51
91 70 93 95 123 140 77 41 26 100 111 23 161 142 36 133 57 92 109 21 50 104
110 149 101 155 134 61 160 129 98 68 33 124 73 126 1 135 152 32 118 138
147 49 139 3 137 31 52 71 13 2 45 127 9 146 108 43 78 86 121 81 153 148 83
156 114 94 116 158 37 74
82 123 152 156 5 23 125 162 96 61 108 92 110 14 20 86 60 75 124 48 129 84
111 24 121 157 37 34 50 30 114 32 113 44 115 58 158 74 88 131 151 19 6 102
80 54 4 126 8 10 51 89 53 29 7 56 12 128 59 90 55 38 35 33 159 16 112 137
69 142 99 72 46 9 101 3 1 78 57 15 141 140 83 146 154 120 130 41 49 43 2
63 65 42 67 91 138 160 97 21 85 66 144 104 105 106 107 109 70 87 95 133 45
81 11 116 149 118 119 100 28 136 93 13 26 52 127 145 153 77 73 36 27 31
135 122 134 94 64 17 161 132 143 103 139 18 147 79 98 150 47 76 71 22 39
68 148 117 62 25 155 40
1 39 89 4 97 21 49 8 12 154 29 27 121 14 79 91 94 158 19 109 132 124 23 84
16 26 157 73 81 28 5 17 47 86 35 80 146 126 71 40 133 90 61 99 111 46 134
48 95 33 51 20 112 156 45 102 57 41 147 60 106 100 161 64 65 66 9 11 74
110 36 15 115 69 63 152 3 118 2 145 30 82 155 58 122 135 120 88 31 98 34
44 150 142 148 96 72 125 92 54 101 128 59 119 105 139 25 78 24 70 153 53
162 62 160 104 68 56 123 18 103 114 87 6 52 136 127 141 32 38 131 117 10
138 140 159 137 13 37 108 116 67 143 130 107 76 113 75 149 85 43 50 22 93
83 55 129 144 7 77 42 151
1 2 4 5 3 8 7 6 9 10 11 13 12 16 15 17 21 22 20 19 18 14 23 24 25 26 28 27
29 36 37 35 38 43 42 41 40 39 34 33 48 49 50 51 52 53 47 46 55 54 45 56 44
58 57 32 31 60 61 62 59 64 65 69 68 72 71 74 73 70 67 75 66 63 30 77 78 79
76 82 81 84 83 85 80 90 91 89 92 94 93 88 95 87 86 96 97 101 102 100 103
105 104 99 98 109 112 111 113 114 110 120 119 125 124 123 126 122 121 127
118 129 131 130 136 135 137 139 138 140 134 133 142 147 146 148 152 153
151 156 157 158 160 159 161 155 154 150 149 145 144 143 141 132 128 117
116 115 108 107 106 162
2 3 1 6 5 7 8 9 14 17 16 19 18 26 25 24 27 29 28 23 30 31 22 34 37 38 39
40 36 42 41 43 44 45 35 46 33 32 47 21 20 15 13 12 48 11 50 52 53 51 49 10
4 55 56 54 58 60 61 59 62 57 64 63 65 66 69 70 71 68 67 76 77 75 79 82 81
80 78 83 74 84 73 85 87 86 88 72 89 90 91 93 92 98 97 101 102 100 99 96
103 104 111 112 113 110 109 108 114 117 122 125 124 127 131 132 130 137
136 138 140 143 145 152 151 150 149 148 153 147 154 146 155 144 142 157
156 141 139 135 159 158 161 160 134 133 129 128 126 123 121 120 119 118
116 115 107 106 105 95 94 162
0
0
sample output.txt
No
Yes
No
No
No
Yes
Yes
MY CODE
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n != 0) {
vector<int> coaches(n);
for (int i = 0; i < n; i++) {
cin >> coaches[i];
}
stack<int> station;
int nextCoach = 1;
bool possible = true;
for (int i = 0; i < n; i++) {
while (!station.empty() && station.top() == nextCoach) {
station.pop();
nextCoach++;
}
if (coaches[i] == nextCoach) {
nextCoach++;
}
else if (!station.empty() && station.top() < coaches[i]) {
possible = false;
break;
}
else {
station.push(coaches[i]);
}
}
if (possible) {
cout << "Yesn";
}
else {
cout << "Non";
}
// Print a blank line after each test case
cout << endl;
}
return 0;
}
MY CODE STACK ADT FOR REQUIREMENT
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
bool can_rearrange_coaches(int n, vector<int> coaches) {
stack<int> stack;
int i = 0;
for (int coach : coaches) {
while (!stack.empty() && stack.top() == i + 1) {
i += 1;
stack.pop();
}
if (coach == i + 1) {
i += 1;
}
else {
stack.push(coach);
}
}
while (!stack.empty() && stack.top() == i + 1) {
i += 1;
stack.pop();
}
return i == n;
}
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
vector<int> coaches;
while (true) {
int coach;
cin >> coach;
if (coach == 0) {
break;
}
coaches.push_back(coach);
}
if (can_rearrange_coaches(n, coaches)) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
cout << endl;
}
return 0;
}
Question for Reference:
Railroad cars numbered 1,2, ..., n on the right track are to be permuted and moved along on the
left track. A car may be moved directly onto the left track, or it may be shunted onto the siding to
be removed at a later time and placed on the left track. The siding thus operates as a stack, a push
operation moving a car from the right track onto the siding and a pop operation moving the "top"
car from the siding onto the left track. For example, when n = 3, push 1, push 2, move 3, pop 2,
pop 1 arranges them in the order 3, 2,1.
Are any permutations not possible? Yes, for example, 312 is an impossible permutation.
Assume that the train arriving from the direction A has N <= 1000 coaches numbered in
increasing order 1, 2, 3,....N. The chief for train reorganizations must know whether it is possible
to marshal coaches continuing in the same direction so that their order will be. Your job is to
help him to write a program that decides whether it is possible to get the required order of
coaches.
Apply stack ADT in the program.

Weitere ähnliche Inhalte

Ähnlich wie NEED TO FIX ERRORS ONLY AND SHOW CODE WORKING- PLEASE USE MY CODE AND.pdf

ROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic Actuator
ROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic ActuatorROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic Actuator
ROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic ActuatorROTEX Controls USA
 
Confidence Interval ExplanationHere is one sample from the before .docx
Confidence Interval ExplanationHere is one sample from the before .docxConfidence Interval ExplanationHere is one sample from the before .docx
Confidence Interval ExplanationHere is one sample from the before .docxmargaretr5
 
Happy, Lucky, Amicable and Sociable Numbers
Happy, Lucky, Amicable and Sociable NumbersHappy, Lucky, Amicable and Sociable Numbers
Happy, Lucky, Amicable and Sociable Numberssheisirenebkm
 
Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10
Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10
Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10Jason Lamberts
 
Isatana measured
Isatana measured Isatana measured
Isatana measured Jason Juen
 
Plano abril ult.pdf
Plano abril ult.pdfPlano abril ult.pdf
Plano abril ult.pdfEdithAQ1
 
Tabel Nilai Kritis Distribusi Chi-Square
Tabel Nilai Kritis Distribusi Chi-SquareTabel Nilai Kritis Distribusi Chi-Square
Tabel Nilai Kritis Distribusi Chi-SquareTrisnadi Wijaya
 
transportation impact study in city of toronto
transportation impact study in city of  torontotransportation impact study in city of  toronto
transportation impact study in city of torontok9048520328
 
1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx
1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx
1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docxdorishigh
 
Matemática financeira 6 tabelas financeiras de alto nível - by prof. shibat...
Matemática financeira   6 tabelas financeiras de alto nível - by prof. shibat...Matemática financeira   6 tabelas financeiras de alto nível - by prof. shibat...
Matemática financeira 6 tabelas financeiras de alto nível - by prof. shibat...prof. Renan Viana
 

Ähnlich wie NEED TO FIX ERRORS ONLY AND SHOW CODE WORKING- PLEASE USE MY CODE AND.pdf (20)

ROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic Actuator
ROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic ActuatorROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic Actuator
ROTEX Controls ECV Rack and Pinion Industrial Valve Pneumatic Actuator
 
Digital Entrepreneurship
Digital EntrepreneurshipDigital Entrepreneurship
Digital Entrepreneurship
 
Confidence Interval ExplanationHere is one sample from the before .docx
Confidence Interval ExplanationHere is one sample from the before .docxConfidence Interval ExplanationHere is one sample from the before .docx
Confidence Interval ExplanationHere is one sample from the before .docx
 
Happy, Lucky, Amicable and Sociable Numbers
Happy, Lucky, Amicable and Sociable NumbersHappy, Lucky, Amicable and Sociable Numbers
Happy, Lucky, Amicable and Sociable Numbers
 
Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10
Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10
Snake North 2010 3D SCHEDULE A 25K Final Version Aug23-10
 
Istana try
 Istana try Istana try
Istana try
 
Istana try
Istana try Istana try
Istana try
 
Isatana measured
Isatana measured Isatana measured
Isatana measured
 
Pneumatic Rack and Pinion Valve Actuators
Pneumatic Rack and Pinion Valve ActuatorsPneumatic Rack and Pinion Valve Actuators
Pneumatic Rack and Pinion Valve Actuators
 
SN-Lecture 13
SN-Lecture 13SN-Lecture 13
SN-Lecture 13
 
Plano abril ult.pdf
Plano abril ult.pdfPlano abril ult.pdf
Plano abril ult.pdf
 
Numeric Palindromes
Numeric PalindromesNumeric Palindromes
Numeric Palindromes
 
EL multibar
EL multibarEL multibar
EL multibar
 
Tabel Nilai Kritis Distribusi Chi-Square
Tabel Nilai Kritis Distribusi Chi-SquareTabel Nilai Kritis Distribusi Chi-Square
Tabel Nilai Kritis Distribusi Chi-Square
 
DCPT_Template 2016
DCPT_Template 2016DCPT_Template 2016
DCPT_Template 2016
 
transportation impact study in city of toronto
transportation impact study in city of  torontotransportation impact study in city of  toronto
transportation impact study in city of toronto
 
1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx
1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx
1) Show images A1a (in gray scale), B1a (in gray scale) and merge;.docx
 
Prime numbers
Prime numbersPrime numbers
Prime numbers
 
Prime numbers
Prime numbersPrime numbers
Prime numbers
 
Matemática financeira 6 tabelas financeiras de alto nível - by prof. shibat...
Matemática financeira   6 tabelas financeiras de alto nível - by prof. shibat...Matemática financeira   6 tabelas financeiras de alto nível - by prof. shibat...
Matemática financeira 6 tabelas financeiras de alto nível - by prof. shibat...
 

Mehr von Edwardw5nSlaterl

On January 19- I sent an announcement about the different types of law.pdf
On January 19- I sent an announcement about the different types of law.pdfOn January 19- I sent an announcement about the different types of law.pdf
On January 19- I sent an announcement about the different types of law.pdfEdwardw5nSlaterl
 
On January 31- a snowstorm damaged the office of a small business- and (3).pdf
On January 31- a snowstorm damaged the office of a small business- and (3).pdfOn January 31- a snowstorm damaged the office of a small business- and (3).pdf
On January 31- a snowstorm damaged the office of a small business- and (3).pdfEdwardw5nSlaterl
 
On June 1- 2013- May and Nora formed a partnership- May is to invest a.pdf
On June 1- 2013- May and Nora formed a partnership- May is to invest a.pdfOn June 1- 2013- May and Nora formed a partnership- May is to invest a.pdf
On June 1- 2013- May and Nora formed a partnership- May is to invest a.pdfEdwardw5nSlaterl
 
On January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdf
On January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdfOn January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdf
On January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdfEdwardw5nSlaterl
 
On January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdf
On January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdfOn January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdf
On January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdfEdwardw5nSlaterl
 
On January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdf
On January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdfOn January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdf
On January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdfEdwardw5nSlaterl
 
On January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdf
On January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdfOn January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdf
On January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdfEdwardw5nSlaterl
 
On January 1- 2020- A- B and C establish a joint undertaking to manufa.pdf
On January 1- 2020- A- B and C establish a joint undertaking to manufa.pdfOn January 1- 2020- A- B and C establish a joint undertaking to manufa.pdf
On January 1- 2020- A- B and C establish a joint undertaking to manufa.pdfEdwardw5nSlaterl
 
On January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdf
On January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdfOn January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdf
On January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdfEdwardw5nSlaterl
 
On fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdf
On fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdfOn fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdf
On fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdfEdwardw5nSlaterl
 
On February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdf
On February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdfOn February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdf
On February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdfEdwardw5nSlaterl
 
Objective Take user inputs and add them to the nested dictionary data.pdf
Objective Take user inputs and add them to the nested dictionary data.pdfObjective Take user inputs and add them to the nested dictionary data.pdf
Objective Take user inputs and add them to the nested dictionary data.pdfEdwardw5nSlaterl
 
On December 31- 20X1- the ledger of Lopez Company contained the follow.pdf
On December 31- 20X1- the ledger of Lopez Company contained the follow.pdfOn December 31- 20X1- the ledger of Lopez Company contained the follow.pdf
On December 31- 20X1- the ledger of Lopez Company contained the follow.pdfEdwardw5nSlaterl
 
OK- here we are with Covid-19 and flu- and the rise of other diseases.pdf
OK- here we are with Covid-19 and flu- and the rise of other diseases.pdfOK- here we are with Covid-19 and flu- and the rise of other diseases.pdf
OK- here we are with Covid-19 and flu- and the rise of other diseases.pdfEdwardw5nSlaterl
 
Of the adult population in the United States- 47- have hypertension- A.pdf
Of the adult population in the United States- 47- have hypertension- A.pdfOf the adult population in the United States- 47- have hypertension- A.pdf
Of the adult population in the United States- 47- have hypertension- A.pdfEdwardw5nSlaterl
 
Obtain the demand functions of x and y for the following utility funct.pdf
Obtain the demand functions of x and y for the following utility funct.pdfObtain the demand functions of x and y for the following utility funct.pdf
Obtain the demand functions of x and y for the following utility funct.pdfEdwardw5nSlaterl
 
Obtain a copy of the City of Orlando government's annual operating bud.pdf
Obtain a copy of the City of Orlando government's annual operating bud.pdfObtain a copy of the City of Orlando government's annual operating bud.pdf
Obtain a copy of the City of Orlando government's annual operating bud.pdfEdwardw5nSlaterl
 
Obtain a copy of the City of Orlando government's annual operating bud (1).pdf
Obtain a copy of the City of Orlando government's annual operating bud (1).pdfObtain a copy of the City of Orlando government's annual operating bud (1).pdf
Obtain a copy of the City of Orlando government's annual operating bud (1).pdfEdwardw5nSlaterl
 
Obtain a copy of the City of Orlando government's annual operating bud (4).pdf
Obtain a copy of the City of Orlando government's annual operating bud (4).pdfObtain a copy of the City of Orlando government's annual operating bud (4).pdf
Obtain a copy of the City of Orlando government's annual operating bud (4).pdfEdwardw5nSlaterl
 
Obtain a copy of the City of Orlando government's annual operating bud (2).pdf
Obtain a copy of the City of Orlando government's annual operating bud (2).pdfObtain a copy of the City of Orlando government's annual operating bud (2).pdf
Obtain a copy of the City of Orlando government's annual operating bud (2).pdfEdwardw5nSlaterl
 

Mehr von Edwardw5nSlaterl (20)

On January 19- I sent an announcement about the different types of law.pdf
On January 19- I sent an announcement about the different types of law.pdfOn January 19- I sent an announcement about the different types of law.pdf
On January 19- I sent an announcement about the different types of law.pdf
 
On January 31- a snowstorm damaged the office of a small business- and (3).pdf
On January 31- a snowstorm damaged the office of a small business- and (3).pdfOn January 31- a snowstorm damaged the office of a small business- and (3).pdf
On January 31- a snowstorm damaged the office of a small business- and (3).pdf
 
On June 1- 2013- May and Nora formed a partnership- May is to invest a.pdf
On June 1- 2013- May and Nora formed a partnership- May is to invest a.pdfOn June 1- 2013- May and Nora formed a partnership- May is to invest a.pdf
On June 1- 2013- May and Nora formed a partnership- May is to invest a.pdf
 
On January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdf
On January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdfOn January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdf
On January 4- 2019- the DJIA opened at 11-739-19- The divisor at that.pdf
 
On January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdf
On January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdfOn January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdf
On January 1-1988- Antonio invests $9-400 in an investment fund- On Ja.pdf
 
On January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdf
On January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdfOn January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdf
On January 1- Southwest College received $1-270-000 in Unearned Tuitio.pdf
 
On January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdf
On January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdfOn January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdf
On January 1- 2020- Pharoah Corporation had 96-000 shares of no-par co.pdf
 
On January 1- 2020- A- B and C establish a joint undertaking to manufa.pdf
On January 1- 2020- A- B and C establish a joint undertaking to manufa.pdfOn January 1- 2020- A- B and C establish a joint undertaking to manufa.pdf
On January 1- 2020- A- B and C establish a joint undertaking to manufa.pdf
 
On January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdf
On January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdfOn January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdf
On January 1 - Daniel borrows $5100 with a fixed annual interest rate.pdf
 
On fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdf
On fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdfOn fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdf
On fune 1- 20v7- Young Corporation paid $20-000 cash for machinery tha.pdf
 
On February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdf
On February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdfOn February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdf
On February 1- 2023- Tessa Williams and Audrey Xie formed a partnershi.pdf
 
Objective Take user inputs and add them to the nested dictionary data.pdf
Objective Take user inputs and add them to the nested dictionary data.pdfObjective Take user inputs and add them to the nested dictionary data.pdf
Objective Take user inputs and add them to the nested dictionary data.pdf
 
On December 31- 20X1- the ledger of Lopez Company contained the follow.pdf
On December 31- 20X1- the ledger of Lopez Company contained the follow.pdfOn December 31- 20X1- the ledger of Lopez Company contained the follow.pdf
On December 31- 20X1- the ledger of Lopez Company contained the follow.pdf
 
OK- here we are with Covid-19 and flu- and the rise of other diseases.pdf
OK- here we are with Covid-19 and flu- and the rise of other diseases.pdfOK- here we are with Covid-19 and flu- and the rise of other diseases.pdf
OK- here we are with Covid-19 and flu- and the rise of other diseases.pdf
 
Of the adult population in the United States- 47- have hypertension- A.pdf
Of the adult population in the United States- 47- have hypertension- A.pdfOf the adult population in the United States- 47- have hypertension- A.pdf
Of the adult population in the United States- 47- have hypertension- A.pdf
 
Obtain the demand functions of x and y for the following utility funct.pdf
Obtain the demand functions of x and y for the following utility funct.pdfObtain the demand functions of x and y for the following utility funct.pdf
Obtain the demand functions of x and y for the following utility funct.pdf
 
Obtain a copy of the City of Orlando government's annual operating bud.pdf
Obtain a copy of the City of Orlando government's annual operating bud.pdfObtain a copy of the City of Orlando government's annual operating bud.pdf
Obtain a copy of the City of Orlando government's annual operating bud.pdf
 
Obtain a copy of the City of Orlando government's annual operating bud (1).pdf
Obtain a copy of the City of Orlando government's annual operating bud (1).pdfObtain a copy of the City of Orlando government's annual operating bud (1).pdf
Obtain a copy of the City of Orlando government's annual operating bud (1).pdf
 
Obtain a copy of the City of Orlando government's annual operating bud (4).pdf
Obtain a copy of the City of Orlando government's annual operating bud (4).pdfObtain a copy of the City of Orlando government's annual operating bud (4).pdf
Obtain a copy of the City of Orlando government's annual operating bud (4).pdf
 
Obtain a copy of the City of Orlando government's annual operating bud (2).pdf
Obtain a copy of the City of Orlando government's annual operating bud (2).pdfObtain a copy of the City of Orlando government's annual operating bud (2).pdf
Obtain a copy of the City of Orlando government's annual operating bud (2).pdf
 

Kürzlich hochgeladen

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Kürzlich hochgeladen (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

NEED TO FIX ERRORS ONLY AND SHOW CODE WORKING- PLEASE USE MY CODE AND.pdf

  • 1. NEED TO FIX ERRORS ONLY AND SHOW CODE WORKING. PLEASE USE MY CODE AND ADD INPUT OUTPUT FILES. IN A HURRY WILL UPVOTE NEED TO ADD THESE TWO FILES BUT KEPT GETTING ERRORS input.txt: 162 10 139 138 4 28 117 63 31 48 74 11 49 118 52 128 153 130 47 17 95 110 18 70 24 112 26 64 115 141 30 87 8 46 34 80 36 13 38 39 102 61 76 120 23 156 106 116 68 85 147 59 121 78 37 53 50 54 91 101 60 94 22 107 71 123 6 67 103 145 152 75 134 73 108 25 140 77 104 127 20 81 2 154 96 151 86 135 88 89 90 58 1 93 161 29 35 97 56 79 82 124 19 7 142 21 143 100 129 109 146 111 5 98 55 45 133 43 16 148 92 113 42 65 83 125 126 114 51 3 62 144 157 150 57 40 136 137 159 162 131 119 69 44 99 158 14 33 9 149 105 15 32 41 12 155 122 132 84 66 72 160 27 1 2 6 5 9 8 7 4 3 12 11 13 10 17 18 20 22 21 25 31 30 32 33 29 34 35 28 41 40 42 39 43 38 46 47 48 51 50 49 45 52 44 56 55 54 53 37 57 36 58 59 60 27 26 61 62 24 23 19 16 65 66 64 67 68 63 15 75 74 73 72 76 77 79 80 82 83 81 85 88 87 94 93 95 92 96 97 91 90 99 102 101 104 105 103 107 111 110 109 108 106 100 112 98 89 114 117 116 118 115 113 119 121 120 123 122 124 126 127 128 130 129 125 131 132 135 136 139 138 140 137 134 133 142 145 148 149 147 153 155 154 152 151 156 150 146 144 160 159 158 157 161 143 141 86 84 78 71 70 69 14 162 144 44 136 40 128 141 8 115 125 131 58 55 145 14 64 28 19 59 76 48 25 16 20 27 7 143 63 112 17 30 65 34 39 130 117 67 82 120 85 154 107 42 151 99 96 46 47 159 162 22 66 12 53 157 113 38 97 11 29 18 10 24 60 75 4 132 90 122 56 79 119 72 150 80 103 35 106 102 15 54 69 6 62 105 5 84 87 88 89 51 91 70 93 95 123 140 77 41 26 100 111 23 161 142 36 133 57 92 109 21 50 104 110 149 101 155 134 61 160 129 98 68 33 124 73 126 1 135 152 32 118 138 147 49 139 3 137 31 52 71 13 2 45 127 9 146 108 43 78 86 121 81 153 148 83 156 114 94 116 158 37 74 82 123 152 156 5 23 125 162 96 61 108 92 110 14 20 86 60 75 124 48 129 84 111 24 121 157 37 34 50 30 114 32 113 44 115 58 158 74 88 131 151 19 6 102 80 54 4 126 8 10 51 89 53 29 7 56 12 128 59 90 55 38 35 33 159 16 112 137 69 142 99 72 46 9 101 3 1 78 57 15 141 140 83 146 154 120 130 41 49 43 2 63 65 42 67 91 138 160 97 21 85 66 144 104 105 106 107 109 70 87 95 133 45 81 11 116 149 118 119 100 28 136 93 13 26 52 127 145 153 77 73 36 27 31 135 122 134 94 64 17 161 132 143 103 139 18 147 79 98 150 47 76 71 22 39 68 148 117 62 25 155 40 1 39 89 4 97 21 49 8 12 154 29 27 121 14 79 91 94 158 19 109 132 124 23 84 16 26 157 73 81 28 5 17 47 86 35 80 146 126 71 40 133 90 61 99 111 46 134 48 95 33 51 20 112 156 45 102 57 41 147 60 106 100 161 64 65 66 9 11 74 110 36 15 115 69 63 152 3 118 2 145 30 82 155 58 122 135 120 88 31 98 34 44 150 142 148 96 72 125 92 54 101 128 59 119 105 139 25 78 24 70 153 53 162 62 160 104 68 56 123 18 103 114 87 6 52 136 127 141 32 38 131 117 10
  • 2. 138 140 159 137 13 37 108 116 67 143 130 107 76 113 75 149 85 43 50 22 93 83 55 129 144 7 77 42 151 1 2 4 5 3 8 7 6 9 10 11 13 12 16 15 17 21 22 20 19 18 14 23 24 25 26 28 27 29 36 37 35 38 43 42 41 40 39 34 33 48 49 50 51 52 53 47 46 55 54 45 56 44 58 57 32 31 60 61 62 59 64 65 69 68 72 71 74 73 70 67 75 66 63 30 77 78 79 76 82 81 84 83 85 80 90 91 89 92 94 93 88 95 87 86 96 97 101 102 100 103 105 104 99 98 109 112 111 113 114 110 120 119 125 124 123 126 122 121 127 118 129 131 130 136 135 137 139 138 140 134 133 142 147 146 148 152 153 151 156 157 158 160 159 161 155 154 150 149 145 144 143 141 132 128 117 116 115 108 107 106 162 2 3 1 6 5 7 8 9 14 17 16 19 18 26 25 24 27 29 28 23 30 31 22 34 37 38 39 40 36 42 41 43 44 45 35 46 33 32 47 21 20 15 13 12 48 11 50 52 53 51 49 10 4 55 56 54 58 60 61 59 62 57 64 63 65 66 69 70 71 68 67 76 77 75 79 82 81 80 78 83 74 84 73 85 87 86 88 72 89 90 91 93 92 98 97 101 102 100 99 96 103 104 111 112 113 110 109 108 114 117 122 125 124 127 131 132 130 137 136 138 140 143 145 152 151 150 149 148 153 147 154 146 155 144 142 157 156 141 139 135 159 158 161 160 134 133 129 128 126 123 121 120 119 118 116 115 107 106 105 95 94 162 0 0 sample output.txt No Yes No No No Yes Yes MY CODE #include <iostream> #include <stack> #include <vector> using namespace std; int main() { int n; while (cin >> n && n != 0) { vector<int> coaches(n); for (int i = 0; i < n; i++) { cin >> coaches[i]; }
  • 3. stack<int> station; int nextCoach = 1; bool possible = true; for (int i = 0; i < n; i++) { while (!station.empty() && station.top() == nextCoach) { station.pop(); nextCoach++; } if (coaches[i] == nextCoach) { nextCoach++; } else if (!station.empty() && station.top() < coaches[i]) { possible = false; break; } else { station.push(coaches[i]); } } if (possible) { cout << "Yesn"; } else { cout << "Non"; } // Print a blank line after each test case cout << endl; } return 0; } MY CODE STACK ADT FOR REQUIREMENT #include <iostream> #include <vector> #include <stack> using namespace std; bool can_rearrange_coaches(int n, vector<int> coaches) { stack<int> stack; int i = 0;
  • 4. for (int coach : coaches) { while (!stack.empty() && stack.top() == i + 1) { i += 1; stack.pop(); } if (coach == i + 1) { i += 1; } else { stack.push(coach); } } while (!stack.empty() && stack.top() == i + 1) { i += 1; stack.pop(); } return i == n; } int main() { while (true) { int n; cin >> n; if (n == 0) { break; } vector<int> coaches; while (true) { int coach; cin >> coach; if (coach == 0) { break; } coaches.push_back(coach); } if (can_rearrange_coaches(n, coaches)) { cout << "Yes" << endl;
  • 5. } else { cout << "No" << endl; } cout << endl; } return 0; } Question for Reference: Railroad cars numbered 1,2, ..., n on the right track are to be permuted and moved along on the left track. A car may be moved directly onto the left track, or it may be shunted onto the siding to be removed at a later time and placed on the left track. The siding thus operates as a stack, a push operation moving a car from the right track onto the siding and a pop operation moving the "top" car from the siding onto the left track. For example, when n = 3, push 1, push 2, move 3, pop 2, pop 1 arranges them in the order 3, 2,1. Are any permutations not possible? Yes, for example, 312 is an impossible permutation. Assume that the train arriving from the direction A has N <= 1000 coaches numbered in increasing order 1, 2, 3,....N. The chief for train reorganizations must know whether it is possible to marshal coaches continuing in the same direction so that their order will be. Your job is to help him to write a program that decides whether it is possible to get the required order of coaches. Apply stack ADT in the program.