-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChoose Items For Highest Discount..cpp
More file actions
57 lines (47 loc) · 1.04 KB
/
Copy pathChoose Items For Highest Discount..cpp
File metadata and controls
57 lines (47 loc) · 1.04 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 <sstream>
#include <string>
#include <limits>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore(); // Handle the newline character after the integer input
string r = "";
double m = numeric_limits<double>::max();
while (n-- > 0) {
string l;
getline(cin, l);
stringstream ss(l);
string a, b, c;
ss >> a >> b >> c;
if (b.empty() || c.empty()) {
continue; // Skip malformed lines
}
try {
double p = stod(b);
double q = stod(c);
double v = (p * q) / 100;
if (v < m) {
m = v;
r = a;
}
} catch (const invalid_argument &e) {
continue; // Skip lines with invalid numbers
}
}
if (r.empty()) {
cout << "Invalid input" << endl;
} else {
cout << r << endl;
}
return 0;
}
Example Input/Output 1:
Input:
3
harddisk 4000 20
monitor 15000 10
laptop 30000 5
Output:
harddisk