0
I have two arrays of multiple strings and I want to print first array elements which are only present in it and not in the other
i.e if some elements of first array are common with the second array then they should not be printed
8 Antworten
+ 9
Kanchan Here, a working C++ code solution. Enjoy! 😁👍🏻
https://code.sololearn.com/c3qGjpB8fYYF/?ref=app
+ 6
# Python
arr1 = ["potato", "doggo", "cheerios", "barbecue", "cream", "lavander", "ice"]
arr2 = ["doggo", "dinosaur", "cream", "robot", "potato", "sandwich"]
for word in arr1:
if word not in arr2:
print(word)
+ 6
Kanchan Well, to be fair, I am not that good in C++, but from what I see you created a class for students and they play Cricket/Badminton.
Is your code compiling when you run it on your IDE? You should first guarantee that your current version is compiling and with no critical bugs before you try adding a new feature. You need to determine which students play only Cricket (and not Badminton), right?
My suggestion is that you take a look at the code I made, run it a couple times and figure out how it is working. Then implement it in your own code as a separate function (so that it can be taken out if it happens to bug the rest of your code, but I do believe it is working well).
Then use the function to determine which students play only Cricket!
Good luck and feel free to ask questions!
+ 1
https://code.sololearn.com/czk4qo4iToPW/?ref=app
This is my code. Can you tell me what is wrong in this code?
+ 1
Eduardo Petry
Yes my code is compiling and giving output same as the input array. I'll try to figure out how your code works. Thank you for your efforts.
+ 1
Error is on line 52: if(name[i] == name1[j]).
What you mention here is probably comparing two words from multidimensional array of chars, but you must notice i.e. name[0] is an array, so compiler converts it to a pointer to the first element of this array -> you compare here memory adresses, not words. Moreover even if you have here arrays of chars insted of pointers, comparison is still invalid becouse c++ lacks of operation comparing two arrays of chars (C - style strings); you must use library functions for such tasks, for example strcmp() from <cstring>. I strongly recommend using std::string class which is modern solution for such kind of problems. Feel free to ask if something is not clear.
0
My question is for c++. Sorry I didn't mention.
0
It is not working. It prints all the elements which are present in first array.(It prints the input)