I can not find out the problem in my code anyone please help..
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <fstream>
using namespace std;
int main ()
{
int stdnum,l=10000;
string qlt;
cin>>stdnum;
cin>>qlt;
int ans[stdnum];
ans[0]=1;
for(int i=0;i<(int)qlt.length();i++)
{
if(qlt[i]=='=')
ans[i+1]=ans[i];
else if(qlt[i]=='R')
ans[i+1]=ans[i]+1;
else if(qlt[i]=='L')
ans[i+1]=ans[i]-1;
}
for(int i=0;i<stdnum;i++)
l=min(l,ans[i]);
if(l<1)
{
l=(-1)*l;
for(int i=0;i<stdnum;i++)ans[i]+=l+1;
}
for(int i=0;i<stdnum;i++)cout<<ans[i]<<" ";
}
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
#include <fstream>
using namespace std;
int main ()
{
int stdnum,l=10000;
string qlt;
cin>>stdnum;
cin>>qlt;
int ans[stdnum];
ans[0]=1;
for(int i=0;i<(int)qlt.length();i++)
{
if(qlt[i]=='=')
ans[i+1]=ans[i];
else if(qlt[i]=='R')
ans[i+1]=ans[i]+1;
else if(qlt[i]=='L')
ans[i+1]=ans[i]-1;
}
for(int i=0;i<stdnum;i++)
l=min(l,ans[i]);
if(l<1)
{
l=(-1)*l;
for(int i=0;i<stdnum;i++)ans[i]+=l+1;
}
for(int i=0;i<stdnum;i++)cout<<ans[i]<<" ";
}
I want to know the proof of correctness.
If you have some idea, could you tell me about it?
In
5
RLLL
Out
1 4 3 2 1
Your answer: 3 4 3 2 1