题目链接:1321: Alphabet Cookies

Description

Kitty likes cookies very much, and especially the alphabet cookies. Now, she get some alphabet cookies, and she wants to select some of them to spell some words.

The easy task for you, is to determine that whether she can spell the word she wants.

Input

The input contains several test cases.

Each test case contains an integer N ( 0 < N ≤ 100 ) in a line.

And followed a line with N capital letters, means the cookies she has.

Then the last line is a word with capital letters. And the word’s length isn’t more than N.

Output

One word for each test case. If she can spell the word by these letters, please output “Yes”, nor output “No”.

Sample Input

7
ARDHPYP
HAPPY
6
ARDHPY
HAPPY

Sample Output

Yes
No

代码

/**
* Time 258ms
* @author wowpH
* @version 1.0
* @date 2019年6月24日下午12:39:59
* Environment: Windows 10
* IDE Version: Eclipse 2019-3
* JDK Version: JDK1.8.0_112
*/ import java.io.InputStreamReader;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(new InputStreamReader(System.in));
while (sc.hasNext()) {
int N = sc.nextInt();
String cookies = sc.next();
String word = sc.next(); int[] lettersNum = new int[26];
for (int i = cookies.length() - 1; i >= 0; --i) {
++lettersNum[cookies.charAt(i) - 'A'];// 统计每个字符的个数
} int i;
for (i = word.length() - 1; i >= 0; --i) {
if (lettersNum[word.charAt(i) - 'A'] <= 0) {// 当前字符不够,退出
break;
}
--lettersNum[word.charAt(i) - 'A'];// 够,个数减1
}
if (i >= 0) {
System.out.println("No");
} else {
System.out.println("Yes");
}
}
sc.close();
}
}

WUSTOJ 1321: Alphabet Cookies(Java)字符统计的更多相关文章

  1. java字符统计+字符串压缩

    要实习了.突然发现自己好像什么都不会,就去看看题吧.在网上看到一个字符串压缩的题.看了一眼,感觉用python很简单.一个for循环+字典就可以搞定. 但是呢,主要还是java.下面就用java来实现 ...

  2. PAT(B) 1042 字符统计(Java)字符串 正则表达式 统计

    题目链接:1042 字符统计 (20 point(s)) 题目描述 请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式 输入在一行中给出一个长度不超过 1000 的字符串.字符串由 A ...

  3. 【字符编码】Java字符编码详细解答及问题探讨

    一.前言 继上一篇写完字节编码内容后,现在分析在Java中各字符编码的问题,并且由这个问题,也引出了一个更有意思的问题,笔者也还没有找到这个问题的答案.也希望各位园友指点指点. 二.Java字符编码 ...

  4. ytu 1910:字符统计(水题)

    字符统计 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 421  Solved: 92[Submit][Status][Web Board] Descri ...

  5. Java 字符编码归纳总结

    String newStr = new String(oldStr.getBytes(), "UTF-8");       java中的String类是按照unicode进行编码的 ...

  6. Java 字符流实现文件读写操作(FileReader-FileWriter)

    Java 字符流实现文件读写操作(FileReader-FileWriter) 备注:字符流效率高,但是没有字节流底层 字节流地址:http://pengyan5945.iteye.com/blog/ ...

  7. PAT-乙级-1042. 字符统计(20)

    1042. 字符统计(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 请编写程序,找出一段给定文字中出现最 ...

  8. 【JAVA编码专题】 JAVA字符编码系列三:Java应用中的编码问题

    这两天抽时间又总结/整理了一下各种编码的实际编码方式,和在Java应用中的使用情况,在这里记录下来以便日后参考. 为了构成一个完整的对文字编码的认识和深入把握,以便处理在Java开发过程中遇到的各种问 ...

  9. 【JAVA编码】 JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换

    http://blog.csdn.net/qinysong/article/details/1179489 这两天抽时间又总结/整理了一下各种编码的实际编码方式,和在Java应用中的使用情况,在这里记 ...

随机推荐

  1. js逆向笔记

    1.nodejs运行js的时候 navigator如果找不到可以可设置为空对象 var navigator={}; 2.使用nodejs如果window对象找不到的时候 可以使用jsdom模块 3.顶 ...

  2. html5中的fieldset/legend元素和keygen元素

    html5中的fieldset/legend元素和keygen元素 一.总结 一句话总结: fieldset/legend元素和figure和figcaption很像,只不过是作用于表单,前者表示内容 ...

  3. Install LEDE on a BT Home Hub 5 / Plusnet One Router

    Overview / Purpose of this guide These instructions are for aimed at users of Windows but a lot of t ...

  4. Unity3d 错误提示 GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced

    程序出現這個問題的話,程序編譯時正確,運行時報錯,而且沒有報出是哪個代碼文件出處. 這個問題一般首先去檢查Level內有用到OnGUI,Debug結果發現某代碼文件在調試代碼時複製多了一行GUILay ...

  5. JVM 数组创建的本质

    1.创建数组 创建一个MyParent4[] 数组 public class MyTest4 { public static void main(String[] args) { MyParent4[ ...

  6. phpexcel 导出xsl乱码

    在header前面加上 ob_end_clean(); ob_end_clean();//清除缓冲区,避免乱码 header('Content-Type: application/vnd.ms-exc ...

  7. 网络流中 InputStream.available() = 0 问题探究

    在处理文件输入流时,通过调用available()方法来获取还有多少字节可以读取,根据该数值创建固定大小的byte数组,从而读取输入流的信息. FileInputStream fi = new Fil ...

  8. Thread.currentThread与this的区别

    在看多线程的时候,看到这个知识点,感觉需要验证一下. 一:线程自启动 1.程序 package com.jun.it.thread; public class MyThread extends Thr ...

  9. JEECG hibernate.hbm2ddl.auto

    配置hibernate根据实体类自动建表功能 - lixuyuan的专栏 - CSDN博客https://blog.csdn.net/lixuyuan/article/details/8057119 ...

  10. 008-MySQL报错-Access denied for user 'root'@'localhost' (using password: NO)

    1.新安装的mysql报错 MySQL报错-Access denied for user 'root'@'localhost' (using password: NO) 解决方案 1.先停掉原来的服务 ...