[백준 16785] ソーシャルゲーム (C#, C++) - soo:bak
작성일 :
문제 링크
설명
누적 코인이 c 이상이 될 때까지 필요한 최소 로그인 횟수를 구하는 문제입니다.
매일 a코인을 받고, 7일 연속 로그인할 때마다 추가로 b코인을 받습니다.
접근법
하루씩 시뮬레이션하며 코인을 누적합니다.
매일 a를 더하고, 7의 배수 날에는 b를 추가로 더합니다.
누적이 c 이상이 되면 종료합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System;
class Program {
static void Main() {
var line = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
var a = line[0];
var b = line[1];
var c = line[2];
var days = 0;
var coins = 0;
while (coins < c) {
days++;
coins += a;
if (days % 7 == 0) coins += b;
}
Console.WriteLine(days);
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, c;
if (!(cin >> a >> b >> c)) return 0;
int days = 0;
int coins = 0;
while (coins < c) {
++days;
coins += a;
if (days % 7 == 0) coins += b;
}
cout << days << "\n";
return 0;
}