#32241: 找不到問題求解


c110110157@nkust.edu.tw (只解簡單的)


請問這是什麼意思?
系統呼叫了 abort 函式! terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)
程式碼如下
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(void){
    cin.tie(0);
    int n,n2,ans; 
    cin >> n;
    vector<int> v;
    while(n-- ){
        cin >> n2;
        v.push_back(n2);
    }
    sort(v.begin(),v.end());
    cout << v[(v.size()-1)/2] << endl;
    return 0;
}
#32244: Re: 找不到問題求解


cges30901 (cges30901)


請問這是什麼意思?
系統呼叫了 abort 函式! terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)
程式碼如下
#include
#include
#include
using namespace std;
int main(void){
    cin.tie(0);
    int n,n2,ans; 
    cin >> n;
    vector v;
    while(n-- ){
        cin >> n2;
        v.push_back(n2);
    }
    sort(v.begin(),v.end());
    cout << v[(v.size()-1)/2] << endl;
    return 0;
}


大概是記憶體不夠?這題應該是考計數排序吧