ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1026. Questions and Answers

CRASH
Posted by d000179 16 Jun 2009 13:18
Could anyone help me?
This code get CRASH...

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
// Input Database
int num_elem_db;
cin >> num_elem_db;
vector<int> data_vector (num_elem_db, 0); // Vector for data
for (int i = 0; i < num_elem_db; ++i)
{
   int aux_elem;
   cin >> aux_elem;
   data_vector[i] = aux_elem;
}
cout << "###" << endl;
// SORTING VECTOR OF DATA
sort( data_vector.begin( ), data_vector.end( ) );
// Input queries
int num_queries;
cin >> num_queries;
vector<int> query_vector (num_queries, 0); // Vector for queries
for (int j = 0; j < num_queries; ++j)
{
   int aux_query;
   cin >> aux_query;
   query_vector[j] = aux_query;
}
for (int k = 0; k < num_queries; ++k)
{
   cout << data_vector[query_vector[k]-1] << endl;
}
return 0;
}