Problem Statement:
NAtural DIAlogue team at Orange labs has an abbreviation "Nadia Team".

This abbreviation causes a big problem for them in Egypt as a lot of Egyptians think this team is owned by a female called nadia and they don't know they are working on NAtural DIAlogue.
To solve their problem they put their name encrypted on the articles and forgot how to decrypt their name.
The encryption was done by putting nadia characters on the article scattered and they will consider an article related to them if they can delete as many characters as they need to form word "nadia".

Can you write a program to help them to check if the given article belongs to them or not?

Input Format:
The first line contains an integer T, the number of test cases. Followed by T lines, each line contains a test case which consists of a string representing the article, which may contain the word "nadia" typed. This line consists of small Latin letters, and its length is not less than 1 and not more than 100 letters.

Output Format:
For each test case, print a single line containing "YES" if you can delete 0 or more characters to get the string "nadia" (without rearranging the remaining characters), otherwise print "NO".

Sample Input:
3 anhaldillooa nnaaddiiaa nxzdiao

Sample Output:

1 Year
Discussion Span
Last Post by David W

We will not do your homework for you. If you have a problem with the code you have then post the code and what the problem is.


You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

There are lots of people here who will freely give their time to help you become the best programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"


Since this was your very first post at Dani's 'student friendly' place ...

Do you have any idea how to start?

  1. Is your data to be read from file ...
    or ...
  2. is it to be entered by the user via the keyboard after a prompt ...
    or ...
  3. is your program to handle both of the above cases?

If you have the 2nd case above ...

you could use an input loop something like this ...

int main()
        string line = takeInLine( "Enter a number followed by that many strings: " );
        vector< string > vec = split( line, " " );
        for( size_t i = 1; i < vec.size(); ++ i )
             process( vec[i] );
    while( more() );

Now, of course, before you could call any (user defined) functions ...
you would have to define them ...

For example:

void process( const string& str )
    // your code goes here //

One way to handle processing the above string
would be to traverse it from beginning to end
and trying to build up a new string
that becomes the desired word ...
i.e to see if that 'string_built_up' == "nadia"

std::string word = "";
std::string seek = "nadia";
int seeklen = seek.size();
int maxlen = str.size();

int i = 0, j = 0;

for( ; i < maxlen; ++ i )
    if( str[i] == seek[j] )
        word += str[i]; // build up word //
        if( word == seek.substr(0, j) )
            if( j == seeklen ) // done, i.e. have the word //
        else if( str[i] == seek[0] ) // start again //
            word = str[i];
            j = 1;

cout << "For '" << str << "', '" << word << "'";

// test end conditions
cout << " ... the word '"<< seek;
if( seek == word )
    cout << "' was found.\n";
    cout << "' was NOT found.\n";

Edited by David W

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.