-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheap Choices.cpp
More file actions
57 lines (48 loc) · 1.31 KB
/
Cheap Choices.cpp
File metadata and controls
57 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
int main()
{
int c;
cin >> c; cin.ignore();
int p;
cin >> p; cin.ignore();
vector<string> items;
for (int i = 0; i < c; i++) {
string item;
getline(cin, item);
items.push_back(item);
}
for (int i = 0; i < p; i++) {
string order;
getline(cin, order);
istringstream iss(order);
string reqCategory, reqSize;
iss >> reqCategory >> reqSize;
int minPrice = -1;
int minIndex = -1;
for (int j = 0; j < items.size(); j++) {
if (items[j] == "") continue;
istringstream itemStream(items[j]);
string category, size;
int price;
itemStream >> category >> size >> price;
if (category == reqCategory && size == reqSize) {
if (minPrice == -1 || price < minPrice) {
minPrice = price;
minIndex = j;
}
}
}
if (minIndex == -1) {
cout << "NONE" << endl;
}
else {
cout << minPrice << endl;
items[minIndex] = "";
}
}
}