p324.ans1
======================
"This is sample-mample"
error
"This is -- -- possible test -- "

=================
p324.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

string text;

bool is_letter(char c) {
    return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}

void read() {
    string line;
    getline(cin, line);
    while(!line.empty() && (line.back() == '\r' || line.back() == '\n')) {
        line.pop_back();
    }
    if(line.size() >= 2 && line.front() == '"' && line.back() == '"') {
        text = line.substr(1, line.size() - 2);
    } else {
        text = "\x01";
    }
}

string dash_string(int k) {
    if(k == 0) {
        return "";
    }
    if(k == 1) {
        return "-";
    }

    string result;
    if(k % 2 == 1) {
        result = " --- ";
        k -= 3;
    } else {
        result = " -- ";
        k -= 2;
    }
    while(k > 0) {
        result += "-- ";
        k -= 2;
    }
    return result;
}

void solve() {
    // This is more of an exercise in parsing. There isn't really a complicated
    // algorithms idea here. We extract words and count dashes between them,
    // then validate that boundary dashes can be expressed as short/long dashes
    // (not single hyphens which require words on both sides).

    vector<string> words;
    vector<int> dashes;

    int dash_count = 0;
    int i = 0;
    while(i < (int)text.size()) {
        char c = text[i];
        if(c == ' ') {
            i++;
        } else if(c == '-') {
            dash_count++;
            i++;
        } else if(is_letter(c)) {
            dashes.push_back(dash_count);
            dash_count = 0;
            string word;
            while(i < (int)text.size() && is_letter(text[i])) {
                word += text[i];
                i++;
            }
            words.push_back(word);
        } else {
            cout << "error\n";
            return;
        }
    }
    dashes.push_back(dash_count);

    if(words.empty()) {
        if(dash_count == 1) {
            cout << "error\n";
        } else if(dash_count > 1) {
            cout << "\"" << dash_string(dash_count) << "\"\n";
        } else {
            cout << "\"\"\n";
        }
        return;
    }

    int n = words.size();
    if(dashes[0] == 1 || dashes[n] == 1) {
        cout << "error\n";
        return;
    }

    ostringstream oss;
    if(dashes[0] > 0) {
        oss << dash_string(dashes[0]);
    }
    oss << words[0];

    for(int j = 1; j < n; j++) {
        int k = dashes[j];
        if(k == 0) {
            oss << " ";
        } else if(k == 1) {
            oss << "-";
        } else {
            oss << dash_string(k);
        }
        oss << words[j];
    }

    if(dashes[n] > 0) {
        oss << dash_string(dashes[n]);
    }

    cout << "\"" << oss.str() << "\"\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }

    return 0;
}

=================
p324.in1
======================
3
"This is sample -mample "
"No solution-"
"This is - - --possible test- -"

=================
statement.txt
======================
324. The Text Formatting
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



The Library of Berland has an ancient document with text composed of words, spaces and "-"  characters. A word is a sequence of Latin letters. The chief librarian asked you to format the text from the document by adding and removing spaces. There are special rules for using the "-"  character in the ancient documents which you need to obey.

The "-"  character can be used as:
Hyphen, in this case a word should be started and finished to the right and to the left from it. For example, "co-coach" .
A part of the short dash, in this case two characters "-"  should be used with a space to the right and to the left. For example, " -- " .
A part of the long dash, in this case three characters "-"  should be used with a space to the right and to the left. For example, " --- " .


If there is no "-"  character between words, the words should be delimited by a single space.

The resulting text should not have any other space characters.

Input
The first line of the input contains N (1 ≤ N ≤ 100) — the number of lines with the text of the document to be formatted. Each of the following N lines contains the quoted text of the document to be formatted. The length of the text of each document is not less than 1 and not more than 100 characters.

Output
For each document from the input write a separate line with the formatted text enclosed in quotes to the output. If it is impossible to correctly format the text, write the only word "error"  without quotes. If there are several solutions, choose any of them.

Example(s)
sample input
sample output
3
"This is sample -mample "
"No solution-"
"This is - - --possible test- -"
"This is sample-mample"
error
"This is -- -- possible test -- "

=================
