-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ20.cpp
More file actions
52 lines (41 loc) · 927 Bytes
/
Q20.cpp
File metadata and controls
52 lines (41 loc) · 927 Bytes
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
#include<iostream>
#include<vector>
using namespace std;
void getData(vector<string>& names, vector<int>& scores) {
while (true) {
string name;
int score;
cin >> name >> score;
if (name == "NoName" && score == 0) {
break;
}
names.push_back(name);
scores.push_back(score);
}
}
void getScore(vector<string> names, vector<int> scores)
{
string name;
cout << "Enter name: ";
cin >> name;
for (int i = 0; i < names.size(); i++)
{
if (names[i] == name)
{
cout << "Score: " << scores[i] << endl;
return;
}
}
cout << "Name not found" << endl;
}
int main() {
cout << "enter a set of name-and-value pairs separated with space" << endl;
vector<string> names;
vector<int> scores;
getData(names, scores);
for (int i = 0; i < names.size(); i++) {
cout << names[i] << " " << scores[i] << endl;
}
getScore(names, scores);
return 0;
}