pb/z14
This commit is contained in:
parent
4d82d1d64f
commit
4c3b045667
3 changed files with 102 additions and 0 deletions
32
1sem/programming basics/z14/40.cpp
Normal file
32
1sem/programming basics/z14/40.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
// pb_z14_40.cpp
|
||||||
|
// Горбацевич Андрей
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void write_aa_55(ostream &ost, size_t N);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ifstream inf("in.txt");
|
||||||
|
ofstream fout("out.bin", ios::trunc|ios::binary);
|
||||||
|
if (!inf.is_open() || !fout.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Unable to open file" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int N = 0;
|
||||||
|
inf >> N;
|
||||||
|
write_aa_55(fout, N);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_aa_55(ostream &ost, size_t N) {
|
||||||
|
for (size_t i = 0; i < N; i +=2) {
|
||||||
|
ost << (unsigned char)0xAA;
|
||||||
|
if (i + 1 < N) {
|
||||||
|
ost << (unsigned char)0x55;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
1sem/programming basics/z14/41.cpp
Normal file
35
1sem/programming basics/z14/41.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
// pb_z14_41.cpp
|
||||||
|
// Горбацевич Андрей
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void write_cyclic_one(ostream &ost, size_t N);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ifstream inf("in.txt");
|
||||||
|
ofstream fout("out.bin", ios::trunc|ios::binary);
|
||||||
|
if (!inf.is_open() || !fout.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Unable to open file" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int N = 0;
|
||||||
|
inf >> N;
|
||||||
|
write_cyclic_one(fout, N);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_cyclic_one(ostream &ost, size_t N) {
|
||||||
|
unsigned char cval = 0x01;
|
||||||
|
unsigned char mval = 0x80;
|
||||||
|
for (size_t i = 0; i < N; i +=2) {
|
||||||
|
if (cval >= mval) {
|
||||||
|
cval = 0x01;
|
||||||
|
}
|
||||||
|
ost << cval;
|
||||||
|
cval <<= 1u;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
1sem/programming basics/z14/42.cpp
Normal file
35
1sem/programming basics/z14/42.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
// pb_z14_42.cpp
|
||||||
|
// Горбацевич Андрей
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void write_filling_ones(ostream &ost, size_t N);
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
ifstream inf("in.txt");
|
||||||
|
ofstream fout("out.bin", ios::trunc|ios::binary);
|
||||||
|
if (!inf.is_open() || !fout.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Unable to open file" << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int N = 0;
|
||||||
|
inf >> N;
|
||||||
|
write_filling_ones(fout, N);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_filling_ones(ostream &ost, size_t N) {
|
||||||
|
unsigned char cval = 0b00000000;
|
||||||
|
unsigned char mval = 0b11111111;
|
||||||
|
for (size_t i = 0; i < N; i +=2) {
|
||||||
|
if (cval == mval) {
|
||||||
|
cval = 0b00000000;
|
||||||
|
}
|
||||||
|
ost << cval;
|
||||||
|
cval = (unsigned)(cval << 1u) | 1u;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue