프로그래밍
프로그래머스 C# 피자 나눠먹기1(Math.Celling(), 삼항연산자, P, J)
노마드선샤인
2022. 12. 26. 14:52
728x90
using System;
public class Solution
{
public int solution(int n)
{
return (int)Math.Ceiling((double)n / 7);
}
}
///
using System;
public class Solution
{
public int solution(int n)
{
int answer = n / 7 + (n % 7 == 0 ? 0 : 1);
/* int answer = n/7;
if(n%7 != 0 )
{
answer += 1; 나머지가 0이면 그대로가고, 0이 아니면 1을 더해준다.
}*/
return answer;
}
}
파이썬
///
def solution(n):
return (n - 1) // 7 + 1
자바
class Solution {
public int solution(int n) {
return (n + 6) / 7;
}
}
class Solution {
public int solution(int n) {
int answer = (n%7==0) ? n/7 : n/7 + 1;
return answer;
}
}
728x90