Блог пользователя matavanga

Автор matavanga, 13 лет назад, По-английски
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]<<" ";
           
        }
   
  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

13 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится
13 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
4
RLL
Your answer:
2 3 2 1
Correct answer:
1 3 2 1

and use pastebin
13 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится
but whats the logical error in my code? my code is very simple.
13 лет назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится
A simple test
In
5
RLLL
Out
1 4 3 2 1
Your answer: 3 4 3 2 1
13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
RRRRL=RLLLLL