# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20243 | pk8498 | 분배 (kriii3_Q) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
}
}