C_CPP/02_MENT/Testat/main_02_MENT.cpp

58 lines
1.8 KiB
C++
Raw Normal View History

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-04-17 14:14:38 +02:00
void printPascalString(PascalString string) {
for(int i = 0; i <= string.length; ++i) {
print(string.characters[i]);
}
println("");
}
2018-04-09 20:11:03 +02:00
2018-04-17 14:14:38 +02:00
PascalString dualOr(PascalString a, PascalString b) {
PascalString longString = a.length >= b.length ? a : b;
PascalString shortString = a.length >= b.length ? b : a;
PascalString result = {longString.length};
/*
for(int i = longString.length; i >= 0; --i) {
if(i >= shortString.length) result.characters[i] = '0';
else result.characters[i] = shortString.characters[i];
}
*/
for(int i = 0; i < longString.length; i++) {
if(i <= shortString.length) {
result.characters[i] = longString.characters[i];
//println("lang ", longString.characters[i]);
}
else{
result.characters[i] = longString.characters[i] | shortString.characters[i];
//println("beides ", shortString.characters[i] | longString.characters[i]);
}
}
return result;
2018-04-09 20:11:03 +02:00
}
2018-04-17 14:14:38 +02:00
int main(int argc, char** argv, char** envp) {
printPascalString(dualOr({2, '0', '1'}, {2, '1', '0'}));
printPascalString(dualOr({2, '0', '1'}, {3, '1', '1', '1'}));
printPascalString(dualOr({3, '1', '1', '1'}, {4, '1', '1', '0', '1'}));
printPascalString(dualOr({3, '0', '0', '0'}, {5, '1', '1', '0', '1', '0'}));
printPascalString(dualOr({3, '0', '1', '1'}, {6, '1', '1', '0', '1', '0', '1'}));
printPascalString(dualOr({2, '0', '1'}, {6, '1', '1', '0', '1', '0', '1'}));
printPascalString(dualOr({2, '1', '1'}, {6, '1', '0', '0', '1', '0', '0'}));
return 0;
}