#include <iostream>
#include <string.h>
using namespace std;
int zderzenia[300020];
int main()
{
int n;
string mrowki;
cin>>n;
cin>>mrowki;
while(mrowki.find("PL")<mrowki.length())
{
for(int i=0; i<mrowki.length()-1; i++)
{
if(mrowki[i]=='P' && mrowki[i+1]=='L')
{
mrowki[i]='L';
mrowki[i+1]='P';
zderzenia[i]++;
zderzenia[i+1]++;
}
}
}
for(int i=0; i<n; i++)
{
cout<<zderzenia[i]<<" ";
}
cout<<endl;
return 0;
}
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 | #include <iostream> #include <string.h> using namespace std; int zderzenia[300020]; int main() { int n; string mrowki; cin>>n; cin>>mrowki; while(mrowki.find("PL")<mrowki.length()) { for(int i=0; i<mrowki.length()-1; i++) { if(mrowki[i]=='P' && mrowki[i+1]=='L') { mrowki[i]='L'; mrowki[i+1]='P'; zderzenia[i]++; zderzenia[i+1]++; } } } for(int i=0; i<n; i++) { cout<<zderzenia[i]<<" "; } cout<<endl; return 0; } |
English