#include <iostream>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, l=0, ps =0, ls =0;
cin >> n;
vector<char> mrow;
int czyp =0; // 0 = LLL 1 = LLLLLPP 2 = LLLLPPPPL
for(n; n > 0; n--)
{
char a;
cin >> a;
if(czyp == 0)
{
if(a == 'L')
{
if(n - 1 == 0)
cout << 0;
else
cout << 0 << " ";
}
else
{
czyp = 1;
mrow.push_back(a);
}
}
else
{
if(a == 'L')
{
l++;
czyp = 2;
mrow.push_back(a);
n--;
break;
}
else
{
mrow.push_back(a);
}
}
}
if(czyp == 1)
{
for(int i = mrow.size(); i > 0; i--)
if(i - 1 == 0)
cout << 0;
else
cout << 0 << " ";
}
else if(czyp == 2) //zaczyna się p kończy l
{
for(n; n > 0; n--)
{
char a;
cin >> a;
mrow.push_back(a);
if(a == 'L')
l++;
}
//i teraz program
for(int i = 0; i < mrow.size();i++)
{
int m = mrow[i];
if(m == 'P')
{
ls = ps;
ps = min(l,ps+1);
}
else
{
l--;
ls = ps;
ps = min(l,ps);
}
if(i + 1 == mrow.size())
cout << ls+ps;
else
cout << ls+ps << " ";
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, l=0, ps =0, ls =0; cin >> n; vector<char> mrow; int czyp =0; // 0 = LLL 1 = LLLLLPP 2 = LLLLPPPPL for(n; n > 0; n--) { char a; cin >> a; if(czyp == 0) { if(a == 'L') { if(n - 1 == 0) cout << 0; else cout << 0 << " "; } else { czyp = 1; mrow.push_back(a); } } else { if(a == 'L') { l++; czyp = 2; mrow.push_back(a); n--; break; } else { mrow.push_back(a); } } } if(czyp == 1) { for(int i = mrow.size(); i > 0; i--) if(i - 1 == 0) cout << 0; else cout << 0 << " "; } else if(czyp == 2) //zaczyna się p kończy l { for(n; n > 0; n--) { char a; cin >> a; mrow.push_back(a); if(a == 'L') l++; } //i teraz program for(int i = 0; i < mrow.size();i++) { int m = mrow[i]; if(m == 'P') { ls = ps; ps = min(l,ps+1); } else { l--; ls = ps; ps = min(l,ps); } if(i + 1 == mrow.size()) cout << ls+ps; else cout << ls+ps << " "; } } } |
English