I have two 2d vectors. Both have a column of strings. I have to match both columns based on number of characters matched counted in an order.
All the Elements in both the columns are compared first.
Then character by character comparison is done in such a way that, if a character from the 1st string(from first vector) is found in any part of 2nd string(from second vector), all the previous characters in 2nd string are ignored in further comparisons of those two strings. All the further comparisons must be made from that matched character. The same should be true in all the future comparisons
i.e for example: if there is a word 'Tennessee' in 1st string and 'east tennessee' in second string, character by character search is done. when the T's are matched, while comparing the next alphabet e, the e in east should be ignored, only alphabets after the t should be considered and so on.
the number of characters are to be counted and displayed along with the matched strings.

There can be spaces in the string,
I have tried it, I am not getting errors but i could get any output displayed.
I guess the fault in my code is because of spaces inbetween words,

Can anyone please help me with this, I have to submit it today :(

I am pasting that part of my code:

for (int p = 0; p < array1.size(); p++)
   for (int e = 0; e < array2.size(); e++)
       count = 0;
         int length1 = array1.at(p).at(2).length();
         int length2 = array2.at(e).at(2).length();
            for (int l = 0; l < length1; l++)
                {cout << array1.at(p).at(2)[l]  << " " << array2.at(e).at(2)[s] << "  r compared \n";
                   //cout << array1.at(p).at(2)[l]  << " " << array2.at(e).at(2)[s] << "  r compared \n";
                    if(array1.at(p).at(2)[l] == array2.at(e).at(2)[s])

                 s ++;
       cout << "still looping" << p << " \n";


In the output I could see that in second string, the 1st letter is compared once and then the 9th letter many times depending on 1st string length...I couldn't figure out why I am getting like this, please help me out


Please post how you declared array1 and array2. Are they std::string objects or std::vector<std::string> objects? Or maybe even something else ?

I declared array1 and array2 like this:

typedef vector<string> LINE1;
typedef vector<string> LINE2;

void main()
    string line1;
    vector<LINE1> array1;

    string line2;
    vector<LINE2> array2;

And also if a string from second vector has the matching character (to the string from first vector) two times, the first one should be considered.
In the next iteration all the characters before the first matched string should be ignored.

>>All the Elements in both the columns are compared first.
do you mean that it compares all the columns in array1[0] with all the columns in array2[0] ? Lets assume there are three solumns in row 0 of each vector, like this:

array1[0][0] = "east tennessee";
array1[0][1]= "west virginia";
array1[0][2]= "north cariolina";

array2[0][0]= "virginia";
array2[0][1]= "cariolina";
array2[0][2]= "georgia";

Its not clear (to me) just what you want to do with all those strings. start with the first column in array2 ("virginia") and try to find it in all the columns of array1 (which would be in array1[0][1]) ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.