【每日一题 春季2】3267. 小明上学 & 1603. 设计停车系统

Day2 AcWing 3267. 小明上学
Day2 LeetCode 1603. 设计停车系统

思路

  1. 水题 模拟

代码

3267. 小明上学
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;

int r,y,g;
int n;
int ans;
int k,t;

int main()
{
scanf("%d%d%d",&r,&y,&g);
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&k,&t);
if(k==0||k==1) ans+=t;
else if(k==2) ans+=t+r;
}
cout<<ans<<endl;
}
1603. 设计停车系统
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class ParkingSystem {
public:
int repo[4]={0};
ParkingSystem(int big, int medium, int small) {
repo[1]=big;
repo[2]=medium;
repo[3]=small;
}

bool addCar(int carType) {
if(repo[carType]>0)
{
repo[carType]--;
return true;
}
return false;
}
};

/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/