글
프로그래머스 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
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 짝수와 홀수의 개수(개쉬움, P, J) (0) | 2022.12.26 |
---|---|
프로그래머스 C# 사분면 나누기 점의 위치 구하기(삼항연산자, 3항연산자) (0) | 2022.12.26 |
프로그래머스 C# 배열 원소의 길이(Length, 자바) (0) | 2022.12.26 |
프로그래머스 C# 직각삼각형 출력하기(split, Console.Write, Console.WriteLine, P, J) (0) | 2022.12.26 |
프로그래머스 C# 과일장수(Array.Sort(), JAVA) (0) | 2022.12.26 |