A씨는 게시판 프로그램을 작성하고 있다.
A씨는 게시물의 총 건수와 한 페이지에 보여줄 게시물수를 입력으로 주었을 때 총 페이지수를 리턴하는 프로그램이 필요하다고 한다.
입력 : 총건수(m), 한페이지에 보여줄 게시물수(n) (단 n은 1보다 크거나 같다. n >= 1)
출력 : 총페이지수
A씨가 필요한 프로그램을 작성하시오.
예) 프로그램 수행 시 다음과 같은 결과값이 나와야 함.
| m | n | 출력 |
|---|---|---|
| 0 | 1 | 0 |
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 1 | 10 | 1 |
| 10 | 10 | 1 |
| 11 | 10 | 2 |
function cal(m, n) {
return Math.ceil(m / n);
}
2021年11月10日 16:13
def page_cal(m, n):
page = m//n
if m%n == 0:
return page
elif m%n != 0:
return page + 1
m = int(input("총 게시물 건수를 입력하세요."))
n = int(input("한 page에 보여줄 게시물 수를 입력하세요."))
while n < 1:
n = int(input("잘못 입력되었습니다. 다시 입력하세요."))
else:
print("필요한 page 수는 : %d" % page_cal(m,n))
def TotalPage(m, n):
if m % n == 0:
return m // n
else:
return m // n +1
2021年11月15日 12:40
let m, n, result
function paging(m, n){
result = m / n;
if(m % n != 0) result++;
result=parseInt(result);
console.log(result)
}
paging(0,1)
paging(1,1)
paging(2,1)
paging(1,10)
paging(10,10)
paging(11,10)
2021年11月23日 13:16
public class Ex03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
System.out.println(getCount(m, n));
}
public static int getCount(int all, int eachPage){
int count=0; //m이 0이면 0출력
for(int i = 1; i<=all;i++) { //1~총건수
if(i%eachPage==0) count++; //i%게시물수 나머지가 0이면 count
}
if(all%eachPage!=0)count++;
return count;
}
}
풀이 작성