【发布时间】:2016-03-08 02:51:23
【问题描述】:
- 嗨,我最近一直在使用矢量,但似乎当我输入“3+2+1”左右时,我的预期输出将是“1+2+3”控制台说:“在抛出后调用终止'std::out_of_range' 原始问题的一个实例来自:http://www.codeforces.com/problemset/problem/339/A。我的问题是什么?谢谢帮助!
#include <bits/stdc++.h> using namespace std; int main (){ ios_base::sync_with_stdio(false); cin.tie(NULL); vector <int> a; string str; cin>>str; for(int i = 0; i < str.size(); i++){ if(str[i]!='+') { int c = str[i]-'0'; a.push_back(c); } } sort(a.begin(), a.end()); cout<<a.at(0); for(int j = 1; j < str.size(); j++){ cout<<'+'<<a.at(j); } return 0; }
【问题讨论】: