514 - Rails

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 514 - Rails

Post by lighted »

I sent you PM
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
arash
New poster
Posts: 6
Joined: Wed Feb 19, 2014 10:19 am

Re: 514 - Rails

Post by arash »

can someone say me where is my code is wrong that i get wa ??? :(

Code: Select all

Accepted!
Thanks
Last edited by arash on Fri Feb 27, 2015 3:33 pm, edited 2 times in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 514 - Rails

Post 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.
Check input and AC output for thousands of problems on uDebug!
arash
New poster
Posts: 6
Joined: Wed Feb 19, 2014 10:19 am

Re: 514 - Rails

Post 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
Sebassmaster
New poster
Posts: 2
Joined: Fri Aug 19, 2016 1:51 am

Re: 514 - Rails

Post 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!
Post Reply

Return to “Volume 5 (500-599)”