Technical Support

    • 题目
      • Input
      • Output
    • 翻译
    • 思想
    • 代码
  • 结果

题目

题目传送门
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 t (1≤t≤500). Description of the test cases follows.

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

The second line of each test case consists of n 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.

翻译

题目大概意思就是,每发送一个问题Q,就会有一个或者多个回答Q。给你一个测试例子数,然后,接收测试例子长度,再接收测试例子(一个字符串)。判断这个字符串是否合法。

思想

一开始,我是这样子想的,判断整个字符串的Q和A的数量就好。先遍历一遍,统计整个字符串Q和A的数量。然后,最后一个字母不能为Q,然后,最后一段QA组合里,必须要A的数目大于等于Q。【因为保证整个字符串A的数量大于等于A,最后一段的QA组合中,A的数目也大于等于Q。所以在最后一段前面的QA一定是Q小于等于A】。
本来以为这个思想会天衣无缝,结果还是WA。然后我思考了很久,举出来一个反例。

1
14
QAAAAQQQAAQQAA

这个例子可以避开上面的规则。

其实就最后一段符合要求,但是如果把最后一段去了,倒数第二段就规避了上面的要求。

本来我想着那么就从后往前,一段一段拿出来比较,发现这样太麻烦了。

但是转念一想,为了保证每一个Q至少都有一个A。那么从后往前遍历,必须保证每时每刻的Q的数目都是小于等于A的。一旦出现这种Q大于A的情况,那么就表明整个字符串不符合要求了。

于是问题迎刃而解!

代码

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner reader = new Scanner(System.in);int t = reader.nextInt(); //  the numbers of cases.for (int i = 0; i < t; ++i) {int length = reader.nextInt();// the length of every case.reader.nextLine();// enterString example = reader.nextLine(); // the exampleint num_question = 0;int num_answer = 0;String result = "Yes";char temp = ' ';for (int j = length - 1; j >= 0; --j) {temp = example.charAt(j);if (temp == 'A')++num_answer;else++num_question;if (num_question > num_answer) {result = "No";break;}}System.out.println(result);}}
}

结果

WA了四次,终于AC了!

CF——Technical Support相关推荐

  1. GTank iOS App Technical Support

    GTank iOS App Technical Support For All Email: z253951598@outlook.com TEL: +86-17782749061 App Scree ...

  2. CodeTank iOS App Technical Support

    CodeTank iOS App Technical Support For All Email: z253951598@outlook.com TEL: +86-17782749061 App Sc ...

  3. OneBox Technical Support

    App Technical Support Email:zhang@ziheng.me TEl: +86-18500341723

  4. About the ball Technical support

    About the ball Technical support 有问题的可以留言. 邮箱地址:2556074349@qq.com 地址:陕西省西安市科技二路西安软件园 谢谢! iOS program ...

  5. iOS Technical Support For All-AFastRecord

    App Technical Support Email:arther.liu@qingwen6.com TEl: +86-18512601835

  6. iOS Technical Support For All-Random Colorful

    iOS Technical Support For All-Random Colorful App Technical Support Email:arther.liu@qingwen6.com TE ...

  7. Technical support(技术支持)

    Technical support(技术支持) E-Mail:667661@qq.com

  8. App Technical Support

    App Technical Support  Email:2623374337@qq.com  TEl: +86-13596032251

  9. Fly deer Technical support

    Fly deer Technical support We can provide our address as well as our email address Email:WdjncdmmChn ...

最新文章

  1. spring注解方式注入bean
  2. 在Go语言程序中使用gojson来解析JSON格式文件
  3. 从零认识单片机(9)
  4. u盘启动蓝屏 索尼vaio_U盘重装系统出现蓝屏?不要急,这四个手段轻松帮你解决!...
  5. 四川中职计算机专业考的学校,四川中职学校哪家专业
  6. Zookeeper Watcher(事件监听器)?
  7. (转)让我们原谅齐达内吧!(附一张落泪的照片)
  8. Java Jersey2使用总结
  9. Test: 为WLW添加源代码着色插件WindowsLiveWriter.CNBlogs.CodeHighlighter
  10. 计算机组成原理学习-哈工大《计算机组成原理》第一章
  11. 平板电脑用来C语言编程可以吗,什么平板电脑能够用来编程?
  12. mysql slave_pending_jobs_size_max_MySQL MTS复制: hitting slave_pending_jobs_size_max
  13. python为循环线条增加颜色_python – Matplotlib:如何将线条颜色设置为橙色,并指定线条标记?...
  14. cleardevice
  15. 世界技能大赛夺冠背后,亚马逊云科技如何培养云计算技能人才?
  16. 在线ARM仿真器知识(嵌入式系统设计师必备)
  17. 使用python和sklearn的中文文本多分类实战开发
  18. matlab fm非相干解调,FM调制和相干解调,非相干解调.pdf
  19. VC-VQA: Visual Calibration Mechanism for Visual Question Answering (VQA的视觉校准机制)
  20. uuid php,php生成uuid介绍

热门文章

  1. 起点中文网爬虫实战requests库以及xpath的应用
  2. 用专业为奋斗的人加把劲!平安养老险保险公众宣传日活动圆满结束
  3. VO和PO 有什么区别啊?
  4. java第八讲:多态
  5. JavaScript中的call,apply,bind区别及应用(包含手写call/apply/bind)
  6. c语言黑匡程序,2020年新版C语言实用程序设计100例流程图.docx
  7. windows自动关机(任务计划程序 + exe文件)
  8. Git学习————blibli大学
  9. HTML+CSS(详细版)
  10. Emitted value instead of an instance of Error