SRM 590 1A 2014.5.26
DIV1
250
Problem Statement | |||||||||||||
| Fox Ciel is playing a game with some chess pawns and a strip of paper. The strip of paper is divided into a row of cells. Each cell can contain at most one pawn. | ||||||||||||
Definition | |||||||||||||
|
| ||||||||||||
Limits | |||||||||||||
|
| ||||||||||||
Constraints | |||||||||||||
- | begin will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | begin and target will contain the same number of elements. | ||||||||||||
- | Each character in begin and target will be one of '.', 'L' and 'R'. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
|
| ||||||||||||
1) | |||||||||||||
|
| ||||||||||||
2) | |||||||||||||
|
| ||||||||||||
3) | |||||||||||||
|
| ||||||||||||
4) | |||||||||||||
|
| ||||||||||||
5) | |||||||||||||
|
|
This problemstatement is the exclusive and proprietary property of TopCoder, Inc. Anyunauthorized use or reproduction of this information without the prior writtenconsent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. Allrights reserved.
Code:
#include<string>
#include<cstdio>
#include<vector>
using namespace std;
class FoxAndChess
{
public: string ableToMove(string begin,string target)
{
stringans;
stringS="",T="";
vector<int>L1,L2,R1,R2;
L1.clear();L2.clear();R1.clear();R2.clear();
for(inti=0;i<begin.size();i++)
{
if(begin[i]!='.')
{
S=S+begin[i];
if(begin[i]=='L') L1.push_back(i); else R1.push_back(i);
}
if(target[i]!='.')
{
T=T+target[i];
if(target[i]=='L') L2.push_back(i); else R2.push_back(i);
}
}
for(intj=0;j<S.size();j++)
if(S[j]!=T[j])
{
ans="Impossible";
returnans;
}
for(intk=0;k<L1.size();k++)
{
if(L1[k]<L2[k])
{
ans="Impossible";
returnans;
}
}
for(intk=0;k<R1.size();k++)
{
if(R1[k]>R2[k])
{
ans="Impossible";
returnans;
}
}
ans="Possible";
returnans;
}
};