Nó báo lỗi như này là sao ạ?
terminate called after throwing an instance of ‘std::out_of_range’
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
link hackkerrank: https://www.hackerrank.com/challenges/reduced-string/problem
> #include <bits/stdc++.h>
> using namespace std;
> string super_reduced_string(string s){
> // Complete this function
> int count = -1;
> for(int i=0;i<s.length()-1;i++) if(s.at(i)==s.at(i+1)){ count = i; break;}else{count=-1;}
> while(count != -1){
> s.erase(count,2);
> for(int i=0;i<s.length()-1;i++) if(s.at(i)==s.at(i+1)){ count = i;break;}else{count=-1;}
> }
> return s;
> }
> int main() {
> string s;
> cin >> s;
> string result = super_reduced_string(s);
> cout << result << endl;
> return 0;
> }
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?