-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
``` |