-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.cpp
42 lines (38 loc) · 801 Bytes
/
queue.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
#include<iostream>
#include<queue>
#include <utility>
#include<map>
#include<string>
using namespace std;
queue< pair<string, int> > q;
pair<string, int> pa;
int main()
{
int n, tp, p;
string name;
cin >> n >> p;
pair <string,double> product1 ("tomatoes",3.25);
for(int i = 0; i < n; i++){
cin >> name >> tp;
pa = make_pair(name, tp);
q.push(pa);
}
int sum = 0;
while(!q.empty()){
pa = q.front();
tp = pa.second;
if(tp > p){
pa.second -= p;
sum += p;
pair<string, int> pp;
pp = pa;
q.pop();
q.push(pp);
}else{
sum += tp;
cout << pa.first << " " << sum << endl;
q.pop();
}
}
return 0;
}