-
Notifications
You must be signed in to change notification settings - Fork 4
/
exec6-4.cpp
54 lines (50 loc) · 1.29 KB
/
exec6-4.cpp
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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Name_value {
public:
string name;
int score;
};
int main() {
vector<Name_value> persons;
string name;
int score;
cout << "Please enter name and score pairs, enter \"NoName 0\" to stop\n";
while (cin >> name >> score) {
if (name == "NoName")
break;
persons.push_back({name, score});
}
cout << "Please enter a query name or score, enter \"q\" to stop\n";
while (true) {
if (cin >> score) {
bool found = false;
for (const Name_value& p : persons)
if (p.score == score) {
cout << p.name << ' ';
found = true;
}
if (found)
cout << '\n';
else
cout << "score not found\n";
}
else {
cin.clear();
cin >> name;
if (name == "q")
break;
bool found = false;
for (const Name_value& p : persons)
if (p.name == name) {
cout << p.score << endl;
found = true;
}
if (!found)
cout << "name not found\n";
}
}
return 0;
}