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 |
m = int(input('총건수 >>'))
n = int(input('한페이지에 보여줄 게시물수 >>'))
total = m//n + int(m%n>0)
print(total)
2023年11月04日 08:53
if m == 0:
return 0
#올림 처리는 (m - 1) // n + 1로 구현 가능
return (m - 1) // n + 1
2024年01月01日 03:29
package codingdojang;
import java.util.*;
public class BoardPaging { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
scanner.nextLine();
int n = scanner.nextInt();
scanner.nextLine();
int result = 0;
if (m % n == 0){
result += (m / n);
} else {
result += (m / n) + 1;
}
System.out.println(result);
}
}
def cnt_total_pages(m, n):
res = 0
if m == 0:
res = 0
elif m % n > 0:
res = m//n + 1
else:
res = m//n
print('%-5d %-5d %d' %(m,n,res))
# m = int(input('총건수(m): '))
# n = int(input('한페이지에 보여줄 게시물수(n):'))
#cnt_total_pages(m, n)
inp = [[0,1],[1,1],[2,1],[1,10],[10,10],[11,10]]
print('m n 출력')
for i in inp:
cnt_total_pages(i[0], i[1])
2024年02月06日 18:09
m = int(input("m의 값 :"))
n = int(input("n의 값 :"))
x = 1
인쇄 = 1
if n >= 1:
while m-x*n > 0:
인쇄 += 1
x += 1
else:
print("한페이지에 보여줄 게시물 수가 0입니다")
print(인쇄)
2024年03月23日 14:37
public static void result(int m, int n) { int result = m / n; if ((m%n) != 0) { result = result + 1; } System.out.println("총 페이지 수 : " + result); }
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = 0;
int n = 0;
System.out.print("총 건수 를 입력하세요 : ");
m = sc.nextInt();
System.out.print("한 페이지에 보여줄 게시물 수를 입력하세요 : ");
n = sc.nextInt();
System.out.println();
result(m,n);
}
}
2024年04月01日 10:36
import math m=int(input("총 게시한 글 수를 입력하세요.")) n=int(input("한 페이지에 보여줄 게시물 수를 알려주세요.")) if m % n == 0: # 만약 30개글인데 3개씩 보여준다. 그러면 10개가 필요함. total = m // n print("총 페이지수는 {}개 입니다.".format(total)) else: total = math.ceil(m / n ) print("총 페이지수는 {}개 입니다.".format(total))
풀이 작성