2018-04-09 20:11:03 +02:00
|
|
|
// file: main_02_MENT.cpp
|
|
|
|
// THIS IS C++, use clang++
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "../../helpers/println.hpp"
|
|
|
|
|
|
|
|
struct PascalString{
|
|
|
|
int length; // number of chars used
|
|
|
|
char characters[256]; // chars of some character string
|
|
|
|
};
|
|
|
|
|
2018-08-22 17:09:40 +02:00
|
|
|
void printPascalString(PascalString s) {
|
|
|
|
for(int i = 0; i <= s.length; ++i) {
|
|
|
|
print(s.characters[i]);
|
2018-04-17 14:14:38 +02:00
|
|
|
}
|
|
|
|
println("");
|
2018-08-22 17:09:40 +02:00
|
|
|
|
2018-04-17 14:14:38 +02:00
|
|
|
}
|
2018-04-09 20:11:03 +02:00
|
|
|
|
2018-08-22 17:09:40 +02:00
|
|
|
PascalString bitwiseDualOr(PascalString a, PascalString b) {
|
2018-09-30 17:34:48 +02:00
|
|
|
|
2018-08-22 17:09:40 +02:00
|
|
|
PascalString shortString = a.length <= b.length ? a : b;
|
|
|
|
PascalString longString = a.length <= b.length ? b : a;
|
2018-04-17 14:14:38 +02:00
|
|
|
|
|
|
|
PascalString result = {longString.length};
|
2018-08-22 17:09:40 +02:00
|
|
|
|
|
|
|
for(int i = 1; i <= shortString.length; ++i) {
|
|
|
|
result.characters[result.length -i] = longString.characters[longString.length -i] | shortString.characters[shortString.length -i];
|
|
|
|
//println(result.length -i, ": ",result.characters[result.length -i]," l=",longString.length -i, ":",longString.characters[longString.length -i]," s=",shortString.length -i,":", shortString.characters[shortString.length -i]);
|
2018-04-17 14:14:38 +02:00
|
|
|
}
|
2018-08-22 17:09:40 +02:00
|
|
|
for(int i = (longString.length - shortString.length)-1; i >= 0 ; --i) {
|
|
|
|
result.characters[i] = longString.characters[i];
|
|
|
|
//println(i, ": ", result.characters[i]);
|
2018-04-17 14:14:38 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 17:09:40 +02:00
|
|
|
return result;
|
2018-04-09 20:11:03 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 17:09:40 +02:00
|
|
|
|
|
|
|
int main(int argc, char** argv, char** envp) {
|
|
|
|
|
|
|
|
printPascalString(bitwiseDualOr({2, '0', '1'}, {2, '1', '0'}));
|
|
|
|
printPascalString(bitwiseDualOr({2, '0', '1'}, {3, '1', '1', '1'}));
|
|
|
|
printPascalString(bitwiseDualOr({3, '1', '1', '1'}, {4, '1', '1', '0', '1'}));
|
|
|
|
printPascalString(bitwiseDualOr({3, '0', '0', '0'}, {5, '1', '1', '0', '1', '0'}));
|
|
|
|
printPascalString(bitwiseDualOr({3, '0', '1', '1'}, {6, '1', '1', '0', '1', '0', '1'}));
|
|
|
|
printPascalString(bitwiseDualOr({2, '0', '1'}, {6, '1', '1', '0', '1', '0', '1'}));
|
|
|
|
printPascalString(bitwiseDualOr({2, '1', '1'}, {6, '1', '0', '0', '1', '0', '0'}));
|
2018-04-17 14:14:38 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|