Page 6 of 6

Re: 514 - Rails

Posted: Mon Oct 27, 2014 5:42 pm
by lighted
I sent you PM

Re: 514 - Rails

Posted: Wed Feb 25, 2015 6:16 pm
by arash
can someone say me where is my code is wrong that i get wa ??? :(

Code: Select all

Accepted!
Thanks

Re: 514 - Rails

Posted: Thu Feb 26, 2015 2:12 am
by brianfry713
In addition, there is one empty line after the lines corresponding to one block of the input file. There should also be a blank line after the last block.

Re: 514 - Rails

Posted: Fri Feb 27, 2015 3:31 pm
by arash
brianfry713 wrote:In addition, there is one empty line after the lines corresponding to one block of the input file. There should also be a blank line after the last block.
oh my god !
everytime i made a silly mistake :) :D
thank you so so so much

Re: 514 - Rails

Posted: Fri Aug 19, 2016 2:05 am
by Sebassmaster
Hi Guys,

I don't know why I'm getting a "Compile Error" from UVA, locally, it compiles just fine and passes all tests:
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <stack>

using Train = std::vector<int>;

bool train_is_valid(Train const& original_train, Train const& train)
{
bool out = true;
std::stack<int> station;
auto current = original_train.cbegin();
for(int const coach : train)
{
if(not station.empty() and coach == station.top())
station.pop();
else
{
auto it = std::find(current, original_train.cend(), coach);
if(it == original_train.cend())
{
out = false;
break;
}
else
{
for_each(current, it, [&station](int const c){station.push(c);});
current = it+1;
}
}

}

return out;
}

std::string annalize_train(Train const& original_train, Train const& train)
{
std::string out = "No";
if(train_is_valid(original_train, train))
out = "Yes";
return out;
}

int main(int argc, char *argv[])
{
std::string line;
while(std::getline(std::cin, line))
{
int n = std::stoi(line);
if(n == 0)
break;

std::getline(std::cin, line);
std::vector<Train> block;
while(line != "0")
{
std::stringstream ss(line);
Train train;
for (int i = 0; i < n; ++i) {
int coach;
ss >> coach;
train.push_back(coach);
}
block.push_back(train);
std::getline(std::cin, line);
}
Train original_train(n);
std::iota(original_train.begin(), original_train.end(), 1);

for(auto const& train : block)
{
std::cout << annalize_train(original_train, train) << std::endl;
}
std::cout << std::endl;
}
return 0;
}

Thank You!