Click here to Skip to main content
14,034,673 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Given n, which is the number of strings taken as input. For each input use have to print “YES” or “NO” whether the current string is already present or not.

Input:
5
Geeks
Hello
Great
Geeks
Hello
Output:

No
No
No
Yes
Yes

What I have tried:

bool isSubSequence(char str1[], char str2[], int m, int n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;
 
    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSequence(str1, str2, m-1, n-1);
 
    // If last characters are not matching
    return isSubSequence(str1, str2, m, n-1);
}
Posted
Updated 6-Sep-18 20:58pm
Comments
Patrice T 7-Sep-18 1:53am
   
And ?
you have a question ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

think about what your code should do: "Look up every new string whether it is already in my array?"

=> so you need to loop every time through the complete array.
a) use a for loop
b) when found you are done
c) after looping all entry you know that you havent found it.
bonus: (only than add it)

You can use some C++ tutorial to learn the basics.

Develop your code and pseudo code yourself to learn programming. Use always a verb and objects.

The first can be: "Ask numbers for input"
   
v2
Comments
Member 13602584 7-Sep-18 3:00am
   
Can you please provide pseudocode, I beginner to programming
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I beginner to programming, can you please provide pseudocode to me
   
Comments
Richard MacCutchan 7-Sep-18 4:47am
   
You have tagged this C and Java, but which is it?
Richard Deeming 7-Sep-18 10:02am
   
1) This is not a solution to your problem, and should not have been posted in the "Add your solution here" box.

2) THIS IS NOT A SOLUTION TO YOUR PROBLEM, and should not have been marked as the "accepted" solution.

3) We do not do your homework for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190423.1 | Last Updated 7 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100