Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

can't understand the error in my solution to 'Decode String'

Правка en1, от AmoDraper, 2022-09-13 06:55:43

Hi Codeforces Community! For the problem 'Decode String' I am getting a strange error, for the sample test case 8 i.e. :- 5 11111 I get am getting a wrong answer, mainly instead of 'aaaaa' I get 'aaaa:' this does not happen when you run this test case indivisually, but when taking all 9 test cases only this one is for some reason outputing wrong answer

Here's my code :-

#include<bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin>>t;
    while (t--) {
        int n;
        cin>>n;
        string arr;
        cin>>arr;
        for(int i = 0 ; i < n ; i++){
            char temp = 48;
            int sum = arr[i];
            if((arr[i+2]) == '0' && (arr[i+3]) != '0') {
                sum = sum*10 + (arr[++i])+32;
                i++;
            }
            temp+=sum;
            cout<<temp;
        }
        cout<<endl;
    }
    return 0;
}

Your Help is Greatly Appreciated. :-)

Теги 820, strings, contest, error

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский AmoDraper 2022-09-13 06:55:43 1034 Initial revision (published)