-
Notifications
You must be signed in to change notification settings - Fork 4
/
exec4-21.cpp
50 lines (47 loc) · 1.28 KB
/
exec4-21.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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<string> names;
vector<int> scores;
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;
names.push_back(name);
scores.push_back(score);
}
cout << "Please enter a query name or score, enter \"q\" to stop\n";
while (true) {
if (cin >> score) {
bool found = false;
for (int i = 0; i < scores.size(); ++i)
if (scores[i] == score) {
cout << names[i] << ' ';
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 (int i = 0; i < names.size(); ++i)
if (names[i] == name) {
cout << scores[i] << endl;
found = true;
}
if (!found)
cout << "name not found\n";
}
}
return 0;
}