Share 904. fruit into baskets c++,

#904.Trái cây vào giỏ C ++, #C ++, #Fruit, #Baskets ## 904. Trái cây vào giỏ (C ++)

Đưa ra một bộ trái cây và một bộ giỏ, hãy tìm số lượng giỏ tối thiểu cần thiết để đặt tất cả các loại trái cây theo cách mà mỗi giỏ chứa nhiều nhất một loại trái cây.

**Ví dụ 1:**

`` `
Đầu vào:
Trái cây = ["A", "B", "C", "A", "B"]]
Baskets = ["A", "B", "C"]]
Đầu ra: 3
Giải trình:
Chúng ta có thể đặt "A" trong giỏ thứ nhất, "B" trong giỏ thứ hai và "C" trong giỏ thứ ba.
`` `

** Ví dụ 2: **

`` `
Đầu vào:
Trái cây = ["A", "B", "C", "D", "E"]]
Baskets = ["A", "B", "C"]]
Đầu ra: 5
Giải trình:
Chúng ta có thể đặt "A" và "B" vào giỏ thứ nhất, "C" trong giỏ thứ hai và "D" và "E" trong giỏ thứ ba.
`` `

**Giải pháp:**

`` `C ++
#include <Istream>
#include <Vector>

sử dụng không gian tên STD;

int main () {
int n, m;
cin >> n >> m;
vector <chuỗi> trái cây (n);
Vector <String> Giỏ (M);
for (int i = 0; i <n; i ++) {
cin >> trái cây ;
}
for (int i = 0; i <m; i ++) {
CIN >> Giỏ ;
}

int ans = 0;
for (int i = 0; i <n; i ++) {
bool tìm thấy = sai;
for (int j = 0; j <m; j ++) {
if (fruits == giỏ [j]) {
tìm thấy = true;
phá vỡ;
}
}
Nếu được tìm thấy) {
ANS ++;
}
}

cout << ans << endl;

trả lại 0;
}
`` `

## hashtags

* #904.Trái cây vào giỏ
* #C ++
* #HOA quả
* #Baskets
* #algorithms
=======================================
#904. Fruit into Baskets C++, #C++, #Fruit, #Baskets ## 904. Fruit into Baskets (C++)

Given a set of fruits and a set of baskets, find the minimum number of baskets needed to put all the fruits in such a way that each basket contains at most one type of fruit.

**Example 1:**

```
Input:
fruits = ["A", "B", "C", "A", "B"]
baskets = ["A", "B", "C"]
Output: 3
Explanation:
We can put "A" in the first basket, "B" in the second basket, and "C" in the third basket.
```

**Example 2:**

```
Input:
fruits = ["A", "B", "C", "D", "E"]
baskets = ["A", "B", "C"]
Output: 5
Explanation:
We can put "A" and "B" in the first basket, "C" in the second basket, and "D" and "E" in the third basket.
```

**Solution:**

```c++
#include <iostream>
#include <vector>

using namespace std;

int main() {
int n, m;
cin >> n >> m;
vector<string> fruits(n);
vector<string> baskets(m);
for (int i = 0; i < n; i++) {
cin >> fruits;
}
for (int i = 0; i < m; i++) {
cin >> baskets;
}

int ans = 0;
for (int i = 0; i < n; i++) {
bool found = false;
for (int j = 0; j < m; j++) {
if (fruits == baskets[j]) {
found = true;
break;
}
}
if (!found) {
ans++;
}
}

cout << ans << endl;

return 0;
}
```

## Hashtags

* #904. Fruit into Baskets
* #C++
* #Fruit
* #Baskets
* #algorithms
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top