• Technical Support


    传送门

    You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.

    Today you need to check a copy of a dialog between a client and a technical support manager. According to the rules of work, each message of the client must be followed by one or several messages, which are the answer of a support manager. However, sometimes clients ask questions so quickly that some of the manager's answers to old questions appear after the client has asked some new questions.

    Due to the privacy policy, the full text of messages is not available to you, only the order of messages is visible, as well as the type of each message: a customer question or a response from the technical support manager. It is guaranteed that the dialog begins with the question of the client.

    You have to determine, if this dialog may correspond to the rules of work described above, or the rules are certainly breached.

    Input

    Each test contains multiple test cases. The first line contains the number of test cases tt (1 \le t \le 5001≤t≤500). Description of the test cases follows.

    The first line of each test case contains one integer nn (1 \le n \le 1001≤n≤100) — the total number of messages in the dialog.

    The second line of each test case consists of nn characters "Q" and "A", describing types of messages in the dialog in chronological order. Character "Q" denotes the message with client question, and character "A" — the message with technical support manager answer. It is guaranteed that the first character in the line equals to "Q".

    Output

    For each test case print "Yes" (without quotes) if dialog may correspond to the rules of work, or "No" (without quotes) otherwise.

    Sample 1

    InputcopyOutputcopy
    5
    4
    QQAA
    4
    QQAQ
    3
    QAA
    1
    Q
    14
    QAQQAQAAQQQAAA
    Yes
    No
    Yes
    No
    Yes
    

    Note

    In the first test case the two questions from the client are followed with two specialist's answers. So this dialog may correspond to the rules of work.

    In the second test case one of the first two questions was not answered.

    In the third test case the technical support manager sent two messaged as the answer to the only message of the client.

    题解:只要每一个提问有且至少一个回复即可,因为回复可能延迟,所以选择从后面开始遍历。如果符合规则,必有 回复的次数大于等于询问的次数

    1. #include
    2. using namespace std;
    3. const int N = 505;
    4. char c[N];
    5. int main()
    6. {
    7. int t;
    8. cin >> t;
    9. while (t--)
    10. {
    11. int n,ta=0,tq=0;
    12. cin >> n;
    13. for (int i = 1; i <= n; i++)
    14. {
    15. cin >> c[i];
    16. }
    17. int f = 1;
    18. for (int i = n; i >=1; i--)
    19. {
    20. if (c[i] == 'Q')
    21. {
    22. tq++;
    23. if (tq > ta)
    24. {
    25. f = 0;
    26. cout << "NO" << endl;
    27. break;
    28. }
    29. }
    30. else
    31. {
    32. ta++;
    33. }
    34. }
    35. if (f)cout << "Yes" << endl;
    36. }
    37. }

  • 相关阅读:
    java基于springboot+vue+elementui的校园疫情防控系统 前后端分离
    《Unity Magica Cloth从入门到详解》之(4)MeshCloth网布
    感受 OpenDNS
    Linux实验五:进程管理
    Spring Boot开发时Java对象和Json对象互转
    SpringCloud Gateway 服务网关的快速入门
    Linux Kernel 之十 虚拟化、VirtIO 架构及规范、VirtQueue & VRing
    猿创征文|基于STM32设计的物联网熏艾空气消毒装置(STM32+华为云IOT)
    【Java八股40天-Day4】 集合类2
    LeetCode-572. Subtree of Another Tree [C++][Java]
  • 原文地址:https://blog.csdn.net/weixin_62599885/article/details/127575049