ACM (TJU) : 2935


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int main ()
{
    int testCase;
    cin >> testCase;

    while ( testCase-- ) {

        string a [10005];

        int n;
        cin >> n;

        for ( int i = 0; i < n; i++ )
            cin >> a [i];

        sort (a, a + n);

        bool flag = true;

        for ( int i = 0; i < n - 1; i++ ) {

            string temp = a [i + 1].substr (0,a[i].length ());

            if ( temp == a [i] ) {
                flag = false;
                break;
            }
        }


        if ( flag )
        cout << "YES" << endl;
        else
        cout << "NO" << endl;

    }

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s