Форум » C/C++ для начинающих (C/C++ for beginners) » 3 array column comparing and split » Ответить

3 array column comparing and split

ramees: int a[]={1,2 ,3,4, 1,1, 6,3 , 1,5,8}; int b[]={2,3 ,8,5, 1,1, 6,3 , 2,6,2}; int c[]={3,7 ,1,2, 2,3, 6,3 , 3,6,1}; i like to split array if column 's are matching high value , mid value , low value based for example you can see my array first column value a[0] = 1 b[0] = 2 c[0] = 3 first i need to find high value , mid value , low value to do that compare them each other so in this case you can see a[0] = 1 is Low value b[0] = 2 is the mid value c[0] = 3 is the high value then find next column high value , mid value , Low value and compare matching . in this case a[0] = {1} low value , a[1] = {2} low value b[0] = {2} mid value , b[1] = {3} mid value c[0] = {3} high value , c[1] = {7} high value all value are matching . incremented array again find the High , Mid, Low values and so on ... output i needed split - 1 1 , 2 2 , 3 3 , 7 split - 2 3 , 4 8 , 5 1 , 2 split - 3 1 , 1 1 , 1 2 , 3 split - 4 6 , 3 6 , 3 6 , 3 split - 5 1,5,8 2,6,2 3,6,1 you can see the last (split -5) is the unmatched value group i did this code but is a bad code how can i do this in a good way

Ответов - 9

Сыроежка: I have not understood how you got the ffifth group. You already showed that a column with values 1 2 3 belongs to the first group. So does it mean that two columns that have the same values can belong to two different groups? As for me then I got the following groups [pre2] 6 3 6 3 6 3 1 1 1 1 2 3 5 6 6 1 2 1 2 3 2 3 7 3 3 4 8 5 1 2 8 2 1 [/pre2] The order of the groups depends on the program algorithm that is used.

ramees: the 5th group is non-matched column's groups array are compare based on array high , mid or low matching to next index of the same array high , mid or low so its not compare array values its compare high , mid ,low that created from the 3array colums so it mean that two columns that have the same values can belong to two different groups your using different array show me the array that u using

Сыроежка: It seems I have understood. You compare only adjacent columns. So as the result if two columns with values 1 2 3 are separated by an element that does not satisfy the comparisons then they belong to different groups.. In my previous example I grouped all elements together independently whether they are adjacent or not.


ramees: use the array that i used my first question and show me result i need to group non-matching adjacent columns too

Сыроежка: In my previous example I used the same arrays as you showed in your first post. Only I grouped them independently whether "equal" elements are adjacent or not. Moreover my groups were sorted starting from the group where all values of a column are equal each other and ending the group where the first value of a column is greater than the second value and the second value is greater than the third value. You could simplify the task if instead of three arrays you used one array of type std::array<int, 3>.

ramees: can u show me the code or what are the steps

Сыроежка: If you have an object of type std::array<int, 3> then you can apply standard algorithm std::adjacent_find to the object according to the criteria. To deal with one container such as std::array<int, 3> is much simpler than with three separate containers because in the first case you can apply standard algorithms.

ramees: i can't use standard algorithms need other way

Сыроежка: It sounds strange because as I said in other your thread standard algorithms are regular template functions. You can of course to write yourself such a function but I do not see any sense.



полная версия страницы