# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
20243 | pk8498 | 분배 (kriii3_Q) | C++98 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <string>
#include <vector>
#include <iostream>
#include <cmath>
namespace test
{
class test
{
public:
virtual void testNum *berDistribution();
};
}
namespace test
{
using org::junit::Test;
void testNum *test::berDistribution()
{
int k = 3;
int n = 1;
if (k == n | k < 1 | n > 16)
{
std::cout << std::string(" Please check the number again. ") << std::endl;
return;
}
// if k>n, swap
if (k > n)
{
k = k ^ n ^ (n = k);
}
// set row,col
int rows = static_cast<int>(std::pow(2, k));
int cols = static_cast<int>(std::pow(2, n - k - 1));
int arrayLength = static_cast<int>(std::pow(2, n));
// set natural number
std::vector<int> number(arrayLength);
for (int i = 0; i < arrayLength; i++)
{
number[i] = i;
}
int count = 0;
// console print
for (int rowIndex = 0; rowIndex < rows; rowIndex++)
{
for (int colIndex = 0; colIndex < cols; colIndex++)
{
std::cout << count << std::string(" ") << number[arrayLength - count - 1];
count++;
if (colIndex > cols - 1)
{
continue;
}
std::cout << std::string(" ");
} // end of colIndex
std::cout << std::endl;
} // end of rowIndex
}
}