I have a problem with the 1237, this problem belongs to the Volume XII.
I leave my code so I can help.
Greetings.
Code: Select all
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Car
{
string name;
int low;
int high;
Car(string n, int l, int h)
{
name = n;
low = l;
high = h;
}
};
int main(int argc, char **argv)
{
int N, numDB, numQuery, val, cont;
cin>>N;
vector<Car*> database;
while(N--)
{
cin>>numDB;
for(int i = 0; i < numDB; i++)
{
string n;
int l, h;
cin>>n>>l>>h;
Car* C = new Car(n,l,h);
database.push_back(C);
}
cin>>numQuery;
while(numQuery--)
{
cont = 0;
cin>>val;
int index = 0;
for(int i = 0; i < numDB; i++)
{
if((val >= database[i]->low) && (val <= database[i]->high))
{
cont++;
index = i;
if(cont > 1) break;
}
}
if(cont == 1) cout<<database[index]->name<<endl;
else cout<<"UNDETERMINED"<<endl;
}
database.clear();
}
return 0;
}