Environment dependent characters? are displayed.

Asked 1 years ago, Updated 1 years ago, 429 views

https://atcoder.jp/contests/abc058/tasks/abc058_b

In the code section below, environment dependent characters? will be displayed.
Why do environment-dependent characters appear?
I would appreciate it if you could let me know.

test values
Input:
xyz
abc

Correct output: xaybzc

current output value
xaybzc �

#include<bits/stdc++.h>

using namespace std;

int main() {
    stringo,e;
    cin>>o>>e;
    
    US>//#stringans=";
    int index = 0;
    for(inti=1;i<=o.size()+e.size();i++){
        an.push_back(o[index]);
        an.push_back(e[index]);
        index++;
    }
    
    cout<ans<<endl;

    return 0;
}

Results

c++

2023-01-21 02:53

1 Answers

In short, index has gone to the point where there are no characters in the loop, so I'm just picking up trash. You know that the suffix o[***] has to be a half-open section of [0...o.size()) right?It's not like that now.

The current code will fail if you try to handle multi-byte characters such as UTF-8.If you need to deal with that, you will have more thoughts.That depends on the question.


2023-01-21 08:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.