If we ignore errors, you can read the numbers in one at a time, and form a string for the first line of output. Forming the string will involve appending a reversed copy to the original. Once the string is formed, you can output that string for the first line. Then replace the first number with a space character, and shrink the string from the back by two characters. Keep doing that until you are done.
This works because the numbers are all single digit.
int main (void)
{
int N;
std::string nums;
std::cin >> N;
for (int i = 0, x; i < N; ++i) {
std::cin >> x;
nums += std::to_string(x) + ' ';
}
nums.append(nums.rbegin() + 1, nums.rend());
for (int i = 0; i < N; ++i) {
std::cout << nums << '\n';
nums[2*i] = ' ';
nums.resize(nums.size()-2);
}
}
0
solved pointers with numbers in backwards [closed]