-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP3213.cpp
76 lines (74 loc) · 1.27 KB
/
P3213.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<vector>
using namespace std;
int getNum(char* s) {
char pizza[3][4] = { "1/4", "1/2", "3/4" };
if (strcmp(s, pizza[0])==0) {
return 1;
}
else if (strcmp(s, pizza[1]) == 0) {
return 2;
}
else if (strcmp(s, pizza[2]) == 0) {
return 3;
}
return -1;
}
int main() {
vector<int> half, quarter, quarter3;
int N, pizzaNum = 0;
scanf("%d",&N);
for (int i = 0; i < N; i++) {
char pizza[4] = { 0 };
scanf("%s", pizza);
int num = getNum(pizza);
if (num == 2) {
if (!half.empty()) {
half.pop_back();
pizzaNum++;
}
else {
half.push_back(num);
}
}
else {
if (num == 1) {
quarter.push_back(num);
}
else {
quarter3.push_back(num);
}
if (!quarter.empty() && !quarter3.empty()) {
quarter.pop_back();
quarter3.pop_back();
pizzaNum++;
}
}
}
if (!half.empty()&&!quarter.empty()) {
half.pop_back();
quarter.pop_back();
pizzaNum++;
}
int a = 0;
while (!quarter.empty()) {
quarter.pop_back();
a++;
}
if (!half.empty()) {
pizzaNum++;
}
while (!quarter3.empty()) {
quarter3.pop_back();
pizzaNum++;
}
pizzaNum += a / 4;
a %= 4;
if (a != 0)
pizzaNum++;
printf("%d\n",pizzaNum);
}//