Skip to content

Commit

Permalink
📝 BOJ solution is posted.
Browse files Browse the repository at this point in the history
  • Loading branch information
soo-bak committed Aug 31, 2023
1 parent b26e0fe commit e60f852
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions algorithm/boj/_posts/2023-08-31-[CreamBread-70].md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
layout: single
title: "[백준 28214] 크림빵 (C#, C++) - soo:bak"
date: "2023-08-31 11:59:00 +0900"
description: 수학, 구현 등을 주제로 하는 백준 28214번 문제를 C++ C# 으로 풀이 및 해설
---

## 문제 링크
[28214번 - 크림빵](https://www.acmicpc.net/problem/28214)

## 설명
`n * k` 개의 빵을 `k` 개 씩 묶어서 판매하며, 크림이 들어있지 않은 빵이 `p` 개 이상인 묶음은 판매할 수 없다면,<br>
<br>
판매 가능한 빵 묶음의 개수가 몇 개인지 구하는 문제입니다. <br>
<br>
- - -

## Code
<b>[ C# ] </b>
<br>

```c#
namespace Solution {
class Program {
static void Main(string[] args) {

var input = Console.ReadLine()!.Split(' ');
var n = int.Parse(input[0]);
var k = int.Parse(input[1]);
var p = int.Parse(input[2]);

var breads = new int[n * k];
input = Console.ReadLine()!.Split(' ');
for (int i = 0; i < n * k; i++)
breads[i] = int.Parse(input[i]);

int sellableBundles = 0;
for (int i = 0; i < n; i++) {
int noCreamCount = 0;
for (int j = i * k; j < (i + 1) * k; j++)
if (breads[j] == 0) noCreamCount++;
if (noCreamCount < p) sellableBundles++;
}

Console.WriteLine(sellableBundles);

}
}
}
```
<br><br>
<b>[ C++ ] </b>
<br>

```c++
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);

int n, k, p; cin >> n >> k >> p;

vi breads(n * k);
for (int i = 0; i < n * k; i++)
cin >> breads[i];

int sellableBundles = 0;
for (int i = 0; i < n; i++) {
int noCreamCount = 0;
for (int j = i * k; j < (i + 1) * k; j++)
if (breads[j] == 0) noCreamCount++;
if (noCreamCount < p) sellableBundles++;
}

cout << sellableBundles << "\n";

return 0;
}
```

0 comments on commit e60f852

Please sign in to comment.