I'm trying to implement a function in C++ that gets two inputs, one input is an array of integers value (binary values just zero or one) , the second input is an integer value one of those values: 1 , 2, 4, 8.
the function returns the correct pre-mapped pattern according to this table: multiple Mapped Value = 0 Mapped Value= 1 1 0 1 2 00 11 4 1100 0011 8 11001100 00110011
I mean by pre-mapped pattern, a pattern that it was before mapping it according to the table !.
to elaborate more, I'm giving examples: (Remap is the name of the function, we always read the given input array from left to right ..)
Ramp(given array, multiply value)
first example: Remap({0,1} , 1 ) => returns an integer array according to the table {0, 1}; (we see that 0 is mapped to value 0 , 1 is mapped to value 0 if the multiply=1)
second example: Remap({1 ,1 , 0 , 0} , 2 ) => returns an integer array according to the table {1 ,0}; (we see that 11 is mapped to value 1 , 00 is mapped to value 0 if the multiply=2, so the output is {1,0})
third example: Remap({1 ,1 , 0 , 0 , 0 , 0 , 1 , 1} , 4 ) => returns an integer array according to the table {0 ,1}; (we see that 1100 is mapped to value 0 , 0011 is mapped to value 1 if the multiply=4 so output is {0,1})
third example: Remap({1 ,1 , 0 , 0 , 1 , 1, 0 , 0} , 8) => returns an integer array according to the table {0}; (we see that 11001100 is mapped to value 0 if the multiply=8 so output is {0} )
the given array is always in its rules according to the table, this means there's no case like the patterns in the given array aren't the same as the patterns on the table, for instance this array {001} with multiply 2 isn't possible .. !
In brief we are returning the pre-mapped pattern according to the attached table of mapping. (the attached table is given by default in the question itself) My implementation code C++ is:
std::vector Remap(int* givenArray , int multiply)
{
vector<int> ret; // result's utput
switch (multiply)
{ case 1
int l[2]={0,1}; // for first opition in the table
for (int i=0;i<2;i++)
ret.puch_back({0,1});
case 2
int l[4]={0 ,0 ,1 ,1}; // for second opition in the table
for (int i=0;i<4;i++)
ret.puch_back({0 ,0 ,1 ,1});
case 4
int l[8]={0 ,0,1 ,1 ,1 ,1 ,0 ,0}; // for third opition in the table
for (int i=0;i<8;i++)
ret.puch_back({0 ,0,1 ,1 ,1 ,1 ,0 ,0});
case 8
int l[16]={0 ,0,1,1,1,1,0,0 ,1,1,0,0,0,0,1,1}; // for fourth opition in the table
for (int i=0;i<16;i++)
ret.puch_back({0 ,0,1,1,1,1,0,0 ,1,1,0,0,0,0,1,1});
}
return ret // returning the pre-mapped array to the function main
}
int main()
{
int MappedPattern[4]={0,0,1,1};
vector<int> PremappedPattern=Remap(MappedPattern , 2 ) // it should return {0,1} because 00 -> 0 ,
//11->1 according to the table over multiply =2
return 0;
}
What's wrong with my code? any help please in my implementation for the problem? honestly Im stuck on this about one week, so it would be appreciated if there's any assistance to solve my problem or any other algorithms suggestions for my problem!
THANKS ALOT.
Aucun commentaire:
Enregistrer un commentaire