#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string filename("file.txt");
std::ofstream ofs;
ofs.open(filename, std::ios::binary);
const int n = 4, array_size = 3, half = n * array_size;
for (int i = 0; i < n; ++i)
{
const int position = ofs.tellp();
ofs.write((n % 2 == 0) ? "abc" : "XYZ", array_size);
ofs.seekp(position + half);
ofs.write((n % 2 == 0) ? "ABC" : "xyz", array_size);
ofs.seekp(position + array_size);
}
ofs.close();
std::cin.get();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KCmludCBtYWluKCkKewoJc3RkOjpzdHJpbmcgZmlsZW5hbWUoImZpbGUudHh0Iik7CglzdGQ6Om9mc3RyZWFtIG9mczsKCW9mcy5vcGVuKGZpbGVuYW1lLCBzdGQ6Omlvczo6YmluYXJ5KTsKCWNvbnN0IGludCBuID0gNCwgYXJyYXlfc2l6ZSA9IDMsIGhhbGYgPSBuICogYXJyYXlfc2l6ZTsKCQoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpCgl7CgkJY29uc3QgaW50IHBvc2l0aW9uID0gb2ZzLnRlbGxwKCk7CgkJb2ZzLndyaXRlKChuICUgMiA9PSAwKSA/ICJhYmMiIDogIlhZWiIsIGFycmF5X3NpemUpOwoJCW9mcy5zZWVrcChwb3NpdGlvbiArIGhhbGYpOwoJCW9mcy53cml0ZSgobiAlIDIgPT0gMCkgPyAiQUJDIiA6ICJ4eXoiLCBhcnJheV9zaXplKTsKCQlvZnMuc2Vla3AocG9zaXRpb24gKyBhcnJheV9zaXplKTsKCX0KCQoJb2ZzLmNsb3NlKCk7CglzdGQ6OmNpbi5nZXQoKTsKCXJldHVybiAwOwp9