Автор | Сообщение |
|
Отправлено: 25.08.14 13:47. Заголовок: 3D vector Row compering
int v[][] = { { 1,1,1,1,2,1,2,2,2,2,3,5,5,5,5,5,57,8,8,7,8,8,8,56,56,56,56, }, { 1,1,8,1,2,1,2,2,2,2,3,5,6,6,5,5,57,8,8,7,8,8,8,56,56,56,56, }, { 1,6,8,1,1,1,2,2,3,3,3,4,4,4,5,5,57,85,8,7,8,8,8,56,56,56,1, } }; i have a 2d array like above i access row by row and split all same adjacent element into a 3D vector like below std::vector<std::vector<std::vector<int>>> j = { { {1,1,1,1},{2},{1}, {2,2,2,2},{3}, {5,5,5,5,5}{57},{8,8},{7},{8,8,8},{56,56,56,56} }, { {1,1},{8},{1},{2},{1},{2,2,2,2},{3},{5},{6,6},{5,5},{57},{8,8},{7},{8,8,8},{56,56,56,56} }, { {1},{6},{8},{1,1,1},{2,2},{3,3,3},{4,4,4},{5,5},{57},{85},{8},{7},{8,8,8},{56,56,56},{1} } }; then i convert 3D vector into ID based 3D vector like below ID VALUE SIZE 0 1 4 std::vector<std::vector<std::vector<int>>> b = { { {0,1,4},{0,2,1},{0,1,1},{0,2,4},{0,3,1},{0,5,5},{0,57,1},{0,8,1},{0,7,1},{0,8,4},{0,56,5} }, { {0,1,2},{0,8,1},{0,1,1},{0,2,1},{0,1,1},{0,2,4},{0, 3,1},{0,5,1},{0,6,2},{0,5,2},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }, { {0,1,1},{0,6,1},{0,8,1},{0,1,3},{0,2,2},{0,3,3},{0,4,3},{2,5,2},{0,57,1},{0,85,1},{0,8,1},{0,7,1},{0,8,3},{0,56,3},{0,1,3} } }; you can see that my ID value is now zero i like to compare adjacent Row by row and give same value split to same ID i try to write this but i am stuck each split element have different size i need help
| |
|
Ответов - 16
[только новые]
|
|
|
Отправлено: 26.08.14 14:29. Заголовок: This array definitio..
This array definition int v[][] = { { 1,1,1,1,2,1,2,2,2,2,3,5,5,5,5,5,57,8,8,7,8,8,8,56,56,56,56, }, { 1,1,8,1,2,1,2,2,2,2,3,5,6,6,5,5,57,8,8,7,8,8,8,56,56,56,56, }, { 1,6,8,1,1,1,2,2,3,3,3,4,4,4,5,5,57,85,8,7,8,8,8,56,56,56,1, } }; is wrong. You have to specify the number of elements that are in each row. That is you have to write int v[][27] = { /*...*/ }; Also is there a typo that in the first row of the vector there is written {0,56,5} instead of {0,56,4}? And I have not understood why one element has ID number 2 : {2,5,2}. Is it also a typo?
| |
|
|
Отправлено: 27.08.14 08:19. Заголовок: sry my mistake this ..
sry my mistake this is the final 3D vector i need to compare to replace zero and Set Id (index starting from 1 to .....) [pre std::vector<std::vector<std::vector<int>>> b = { { {0,1,4},{0,2,1},{0,1,1},{0,2,4},{0,3,1},{0,5,5},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }, { {0,1,2},{0,8,1},{0,1,1},{0,2,1},{0,1,1},{0,2,4},{0, 3,1},{0,5,1},{0,6,2},{0,5,2},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }, { {0,1,1},{0,6,1},{0,8,1},{0,1,3},{0,2,2},{0,3,3},{0,4,3},{0,5,2},{0,57,1},{0,85,1},{0,8,1},{0,7,1},{0,8,3},{0,56,3},{0,1,3} } };`
| |
|
|
Отправлено: 29.08.14 21:26. Заголовок: ramees пишет: you c..
ramees пишет: цитата: | you can see that my ID value is now zero i like to compare adjacent Row by row and give same value split to same ID |
| I am sorry I do not understand what you mean. And what is the row now? Is it for example {0,1,4} or { {0,1,4},{0,2,1},{0,1,1},{0,2,4},{0,3,1},{0,5,5},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }?
| |
|
|
Отправлено: 30.08.14 08:28. Заголовок: this is the row {..
this is the row {0,1,4} { { {0,1,4},{0,2,1},{0,1,1},{0,2,4},{0,3,1},{0,5,5},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }, { {0,1,2},{0,8,1},{0,1,1},{0,2,1},{0,1,1},{0,2,4},{0, 3,1},{0,5,1},{0,6,2},{0,5,2},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} } i need to compare red color row to green each row ({0,1,4}) size is different that where i stuck (the size of the row is last element )
| |
|
|
Отправлено: 31.08.14 00:25. Заголовок: I do not understand...
I do not understand. If this {0,1,4} is a row then all rows have the same size that is equal to 3. So it is unclear what you are trying to do.
| |
|
|
Отправлено: 01.09.14 17:05. Заголовок: {0,1,4} is equal t..
{0,1,4} is equal to 1111 so if compare 2 row like {0,1,4} and {0,1,2} it is like 1111 , 2 , 1 , 2222 11 , 8 , 1 , 2 this is the row i used for above example { { {0,1,4},{0,2,1},{0,1,1},{0,2,4},{0,3,1},{0,5,5},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }, { {0,1,2},{0,8,1},{0,1,1},{0,2,1},{0,1,1},{0,2,4},{0, 3,1},{0,5,1},{0,6,2},{0,5,2},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }
| |
|
|
Отправлено: 02.09.14 11:42. Заголовок: I do not understand ..
I do not understand these records 1111 , 2 , 1 , 2222 11 , 8 , 1 , 2 It is clear that row {0,1,4} contains four 1. But what does 2, 1, 2222 mean? How did you get them?
| |
|
|
Отправлено: 04.09.14 13:08. Заголовок: that is 1111 = {0..
that is 1111 = {0,1,4} 2 = {0,2,1} 1 = {0,1,1} , 2222 = {0,2,4} this i showed from this line = { {0,1,4},{0,2,1},{0,1,1},{0,2,4},{0,3,1},{0,5,5},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }, next 11 , 8 , 1 , 2 is from second row of vector { {0,1,2},{0,8,1},{0,1,1},{0,2,1},{0,1,1},{0,2,4},{0, 3,1},{0,5,1},{0,6,2},{0,5,2},{0,57,1},{0,8,2},{0,7,1},{0,8,3},{0,56,4} }
| |
|
|
Отправлено: 08.09.14 22:33. Заголовок: And what you are try..
And what you are trying to do? Till now I can not understand that. So you have two arrays (or vectors) of triads and what you want to do with them?
| |
|
|
Отправлено: 11.09.14 21:22. Заголовок: for example this is ..
for example this is the my vector i initialize like this because i am using c++ 98 compiler std::vector<std::vector<std::vector<int>>> v; int ary [3][5][3]= {{{0,5,3},{0,4,12},{0,7,1}}, {{0,5,3},{0,4,2 },{0,7,2},{0,4,8},{0,7,2}}, {{0,5,3},{0,4,5 },{0,6,1},{0,4,3},{0,7,5}}}; /* 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 7 5 5 5 4 4 7 7 4 4 4 4 4 4 4 4 7 7 5 5 5 4 4 4 4 4 6 4 4 4 7 7 7 7 7 */ std::vector<std::vector<int>> J; std::vector<int> B; for(int i = 0; i < 3; i++){ v.push_back(J); for(int h = 0; h < 5; h++){ v.push_back(B); for(int j = 0; j < 3; j++){ v[h].push_back(ary[h][j]); } } } i like to get out put like this {{{1,5,3},{2,4,12},{5,7,1}}, {{1,5,3},{2,4,2 },{3,7,2},{2,4,8},{5,7,2}}, {{1,5,3},{2,4,5 },{4,6,1},{2,4,3},{5,7,5}}}; the calculation i wand is down to top the last row of 3D vector v . {{0,5,3},{0,4,5},{0,6,1},{0,4,3},{0,7,5}}}; and its adjacent row {{0,5,3},{0,4,2 },{0,7,2},{0,4,8},{0,7,2}}, so you already know this vector row data is compressed version of this two row 5 5 5 4 4 7 7 4 4 4 4 4 4 4 4 7 7 5 5 5 4 4 4 4 4 6 4 4 4 7 7 7 7 7 than i need to access the row of row {0,5,3} and its adjacent row of row {0,5,3} then find its data is matching in this case the value is 5 its matching so replace the zero to put a new same index to both row of row = first {1,5,3} second {1,5,3} in this case both row have same size (the last element is the actual size of row of row) so it's easy to do but the next row of row first {0,4,5 } second {0,4,2 } it's have different size. so find it's matching or not in this case it's matching so put a new index to it . we have first row of row size is 5 and second is 2 so we have 3 data balance to check from first row so we need to increment second row of row so in this case we have first row of row {2,4,5 } second is {0,7,2} find its matching or not . its not matching so replace zero with new index {3,7,2} now we increment two second row of row so both row size is 2 so we have total size 4 so its means we need to increment second row of row one more time to match first row size so the next row of row is first is = {2,4,5} second = {0,4,8} this case its matching so replace zero with first row ID (2) {2,4,5} {2,4,8} and so on .......... i think some time its need to run twice to get the correct output if the real input like this 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 7 5 5 5 4 4 7 7 7 7 4 4 4 4 4 4 7 7 5 5 5 4 4 4 4 4 6 4 4 4 7 7 7 7 7 the idea behind this control all adjacent same element in a 2d array using a ID(index) i hope you get the idea sorry for late replay i am hard working on a film fx my dead line is near :)
| |
|
|
Отправлено: 15.09.14 20:45. Заголовок: I have not understan..
I have not understood why the first two triads belonging to adjucent rows were converted to {1,5,3}. What does this 1 means? Also it is not clear what is the "balance". It is all too tangled.
| |
|
|
|
Отправлено: 17.09.14 06:43. Заголовок: ok . i convert it l..
i convert it like this {1,5,3} because for reducing memory. this triads {1,5,3} have 3 repetition of 5 what if this 1000 or more . 1 is ID to recognizing same adjacent triads
| |
|
|
Отправлено: 19.09.14 05:11. Заголовок: actually what i wan..
actually what i want is split same adjacent element from this 2d array and i need control over all split to edit or replace value 0 2 4 5 4 0 2 6 8 4 0 0 0 8 4 2 2 8 8 4 2 2 8 4 4
| |
|
|
Отправлено: 20.09.14 20:10. Заголовок: What are there the a..
What are there the adjacent elements in this 2D array? And how are you going to split it?
| |
|
|
Отправлено: 22.09.14 06:54. Заголовок: same elements of 2d..
for your first ! same elements of 2d array both direction (x & y) . splitting an area of 2d array to vector is risk so what i thinking is split row by row same element from x direction and add to vector like my format triads {ID , Value , size} then next row of calculation check it previous row data is connected or not if yes add previous ID to new split if its not connected add new ID
| |
|
|
Отправлено: 26.09.14 00:25. Заголовок: http://shot.qip.ru/0..
| |
|
|
|