serna37's Library

Logo

C++ アルゴリズムとデータ構造のライブラリ

View the Project on GitHub serna37/library-cpp

:heavy_check_mark: 文字列結合
(library/string/join.hpp)

文字列結合

できること

計算量

$O(\vert S \vert)$ (合計長)

使い方

vector<string> v;
string S = join(v, ",");

Verified with

Code

#pragma once
string join(const vector<string> &v, const string &sep) {
    string res;
    for (int i = 0; i < (int)v.size(); ++i) {
        if (0 < i) res += sep;
        res += v[i];
    }
    return res;
}
#line 2 "library/string/join.hpp"
string join(const vector<string> &v, const string &sep) {
    string res;
    for (int i = 0; i < (int)v.size(); ++i) {
        if (0 < i) res += sep;
        res += v[i];
    }
    return res;
}
Back to top page