-
April 24th, 2017, 08:55 AM
#1
2d vector data combination
hi i need help to arrange a 2d vector data combination . i don't know how to ask this . in the code below i created a small version of what i want but when the vector get bigger what i do i can't think an other way
Code:
#include <iostream>
#include <vector>
#include<string>
using namespace std;
int main() {
vector<vector<string>> Data;
vector<string> a;
Data.push_back(a);
Data.push_back(a);
Data.push_back(a);
Data[0].push_back("0af5d24d");
Data[0].push_back("45f2r");
Data[0].push_back("245gd");
Data[0].push_back("0");
Data[0].push_back("02");
Data[1].push_back("df5");
Data[1].push_back("0");
Data[1].push_back("245s1");
Data[2].push_back("754g5h");
Data[2].push_back("f2g1fg45f5");
Data[2].push_back("125");
Data[2].push_back("24415");
for (int i = 0; i < Data[0].size(); i++) {
for (int j = 0; j < Data[1].size(); j++) {
for (int k = 0; k < Data[2].size(); k++) {
cout << Data[0][i] << Data[0][j] << Data[0][k] << endl;
// add all 3 vector data into a 1d char array
}
}
}
return 0;
}
-
April 24th, 2017, 01:14 PM
#2
Re: 2d vector data combination
Code:
for (int i = 0; i < Data[0].size(); i++) {
for (int j = 0; j < Data[1].size(); j++) {
for (int k = 0; k < Data[2].size(); k++) {
cout << Data[0][i] << Data[0][j] << Data[0][k] << endl;
There seems to be a problem with this code. j is from 0 to Data[1].size(), but in the cout statement j is used with Data[0] - same issue with k?? This code only appears to work because in the example Data[0] has more elements present than either Data[1] or Data[2]. But when Data[0] has fewer elements... Do you mean
Code:
cout << Data[0][i] << Data[1][j] << Data[2][k] << endl;
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 24th, 2017, 03:28 PM
#3
Re: 2d vector data combination
yes your right sorry . how can i code the same functionality for big vector ( this vector only have size = 3 , what if i have a vector size that above 1000 )
-
April 25th, 2017, 08:09 AM
#4
Re: 2d vector data combination
what if i have a vector size that above 1000
Apart from the coding nightmare (although you could write a program to generate the code that could then be included in the main program), have you considered the complexity of this. Even if this was re-done using recursion somehow, the run-time complexity ...
What are you trying to achieve?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 25th, 2017, 08:56 AM
#5
Re: 2d vector data combination
run-time complexity is not a problem i am a very patient it not a problem its run over a month or more because i need to find a single answer if there any way to solve this problem plz show me . if its successful i will show you a cool thing
-
April 25th, 2017, 09:03 AM
#6
Re: 2d vector data combination
Yes, but what are you trying to achieve?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 25th, 2017, 09:23 AM
#7
Re: 2d vector data combination
something impossible . trust me its going to be cool plz help
-
April 25th, 2017, 09:26 AM
#8
Re: 2d vector data combination
As don't know the purpose and the usage of the code, we can't provide further assistance.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|