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 |
#include <iostream>
using namespace std;
void main()
{
int totalData;
int limitPage;
int totalPage = 0;
scanf_s("%d %d", &totalData, &limitPage);
cout << "총건수:" << totalData << endl;
cout << "한페이지에 보여줄 게시물 수:" << limitPage << endl;
totalPage = totalData / limitPage;
int a = 0;
if (totalPage == 0 || totalData < limitPage)
{
totalPage = 1;
}
else if (totalData % limitPage != 0 && totalData % limitPage < limitPage)
{
totalPage += 1;
}
cout << "페이지수: " << totalPage << endl;
}
// Math 함수를 이용한 경우
function getTotalPage1(m,n){
var total_page = 0;
total_page = Math.ceil(m / n);
return total_page;
}
// Math 함수를 이용하지 않는 경우
function getTotalPage2(m,n){
var total_page = 0;
total_page = parseInt(m / n);
if(total_page > 0) total_page += 1;
return total_page;
}
2016年08月08日 11:00
def total_page(m, n):
if m == 0:
return 0
elif m == 1:
return 1
if m%n == 0:
return m/n
return m/n +1
print(total_page(0, 1))
print(total_page(1, 1))
print(total_page(2, 1))
print(total_page(1, 10))
print(total_page(10, 10))
print(total_page(11, 10))
static void Main(string[] args)
{
int all; //총건수
int show;// 보여줄 페이징
int allview; // 총 페이징
Console.WriteLine("총건수를 입력하세요");
all = int.Parse(Console.ReadLine());
Console.WriteLine("총건수는:" + all);
Console.WriteLine("보여줄 페이징을 입력하세요");
show = int.Parse(Console.ReadLine());
Console.WriteLine("보여줄 페이징은:" + show);
allview = all / show;
Console.WriteLine("총페이징은"+allview);
}
/* 2016年08月17日.Wed
게시판 페이징
*/
#include <stdio.h>
int main(void)
{
#ifdef MY_ANSWER
int m, n, result;
while (1) {
printf("게시물의 총 건수 : ");
scanf("%d", &m);
printf("한 페이지에 보여줄 게시물 개수 : ");
scanf("%d", &n);
if(m == 0 || n == 0)
printf("|%d| result = %d\n", __LINE__, 0);
else if(m > n)
if(m % n == 0)
printf("|%d| result = %d\n", __LINE__, m / n);
else
printf("|%d| result = %d\n", __LINE__, (m / n) + 1);
else if(m < n || m == n)
printf("|%d| result = %d\n", __LINE__, 1);
}
#elif OTHER_ANSWER
#endif
return 0;
}
def PageConverter(totalList, pageNumber):
totalPageNumber = 0
if totalList < 0 or pageNumber < 0:
return totalPageNumber
(page, divide) = divmod(totalList, pageNumber)
if divide > 0:
totalPageNumber = 1
totalPageNumber += page
return totalPageNumber
print(PageConverter(0,1))
#include <iostream>
int main() {
int m{0}, n{0};
int pages{0};
std::cout << "총건수, 한페이지에 보여줄 게시물수 : ";
std::cin >> m >> n;
if (m > 0)
{
pages = (m <= n) ? 1 : (m % n != 0) ? (m / n) + 1 : m / n;
}
else
{
pages = 0;
}
std::cout << "페이지 수 : " << pages << std::endl;
return 0;
}
c++ 작성
2016年08月30日 03:26
풀이 작성