Skip to content

Commit 69b88ca

Browse files
committed
2 parents 06f6af9 + d72863c commit 69b88ca

2 files changed

Lines changed: 67 additions & 33 deletions

File tree

  • niuke/practice/noob
    • noob93 【模板】队列操作
    • noob94 无法吃午餐的学生数量
Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
11
#include <iostream>
22
#include <queue>
3-
#include <vector>
43
using namespace std;
54

6-
template <typename T>
7-
class Queue_e{
5+
template <typename T> class Queue_e {
6+
7+
queue<T> q;
88

9-
queue<T> q;
109
public:
10+
void push(const T &x) { q.push(x); }
1111

12-
void push(const T& x){
13-
q.push(x);
12+
void pop() {
13+
if (!q.empty()) {
14+
q.pop();
15+
} else {
16+
cout << "ERR_CANNOT_POP\n";
1417
}
18+
}
1519

16-
void pop(){
17-
if(!q.empty()){
18-
q.pop();
19-
}else{
20-
cout << "ERR_CANNOT_POP\n";
21-
}
20+
void front() const {
21+
if (!q.empty()) {
22+
cout << q.front() << '\n';
23+
} else {
24+
cout << "ERR_CANNOT_QUERY\n";
2225
}
26+
}
2327

24-
void front() const {
25-
if(!q.empty()){
26-
cout << q.fornt() << '\n';
27-
}else{
28-
cout << "ERR_CANNOT_QUERY\n";
29-
}
30-
}
31-
32-
void size() const {
33-
cout << q.size() << '\n';
34-
}
35-
36-
bool empty() const {
37-
return q.empty();
38-
}
28+
void size() const { cout << q.size() << '\n'; }
3929

30+
bool empty() const { return q.empty(); }
4031
};
4132

4233
int main() {
43-
Queue_e<int> qe;
44-
int n;cin>> n;
45-
46-
while(n--){
47-
34+
Queue_e<int> qe;
35+
int n;
36+
cin >> n;
37+
38+
while (n--) {
39+
int op;
40+
cin >> op;
41+
switch (op) {
42+
case 1: {
43+
int x;
44+
cin >> x;
45+
qe.push(x);
46+
break;
4847
}
49-
48+
case 2:
49+
qe.pop();
50+
break;
51+
case 3:
52+
qe.front();
53+
break;
54+
case 4:
55+
qe.size();
56+
break;
57+
}
58+
}
59+
return 0;
5060
}
5161
// 64 位输出请用 printf("%lld")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
/**
4+
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
5+
*
6+
*
7+
* @param students int整型vector
8+
* @param sandwiches int整型vector
9+
* @return int整型
10+
*/
11+
int countStudents(vector<int>& students, vector<int>& sandwiches) {
12+
// write code here
13+
int i = 0,j = 0,ans = 0;
14+
while(i < students.size() && j < students.size()){
15+
if(students[i] == sandwiches[j]){
16+
++i;++j;
17+
}else{
18+
++i;
19+
++ans;
20+
}
21+
}
22+
return ans;
23+
}
24+
};

0 commit comments

Comments
 (0)