九度OJ 1009

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    while(cin >> n, n != 0)
    {
        string tree;
        cin >> tree;
        string root;
        root = tree[0];
        string left;
        string right;
        for(int i = 1; i < tree.size(); ++i)
        {
            if(tree[i] > tree[0])
                right += tree[i];
            else
                left += tree[i];
        }
        for(int i = 0; i < n; ++i)
        {
            string temp;
            cin >> temp;
            string a, b, r;
            r = temp[0];
            for(int i = 1; i < temp.size(); ++i)
            {
                if(temp[i] > temp[0])
                    a += temp[i];
                else
                    b += temp[i];
            }
            if(a == right && b == left && r == root)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}

發佈了67 篇原創文章 · 獲贊 11 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章