#37595: 我看錯題目的意思?


benjaminkuo (benjikuo)


請問下列程式碼為何錯誤?(0%)

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

int main() {
    int n, c;
    string str;
    set <int> s;
    cin >> n;
    while (n--) {
        cin >> c;
        s.insert(c);
    }
    for (auto i : s) {
        str +=  ' ' + to_string(i);
    }
    reverse(str.begin(), str.end());
    cout << str << '\n'; 
}

#37597: Re: 我看錯題目的意思?


wilson40804@apps.ntpc.edu.tw (廖偉丞)


請問下列程式碼為何錯誤?(0%)

#include
using namespace std;

int main() {
    int n, c;
    string str;
    set s;
    cin >> n;
    while (n--) {
        cin >> c;
        s.insert(c);
    }
    for (auto i : s) {
        str +=  ' ' + to_string(i);
    }
    reverse(str.begin(), str.end());
    cout << str << '\n'; 
}


你直接reverse那>9的數字怎麼辦?