输入有多组数据。
每组数据包含两个字符串A、B,代表A盒与B盒中的乒乓球,每个乒乓球用一个大写字母表示,即相同类型的乒乓球为相同的大写字母。
字符串长度不大于10000。
每一组输入对应一行输出:如果B盒中所有球的类型在A中都有,并且每种球的数量都不大于A,则输出“Yes”;否则输出“No”。
ABCDFYE CDE<br/>ABCDGEAS CDECDE
Yes<br/>No
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
while(read.hasNextLine()) {
String r = read.nextLine();
String[] boxs = r.split(" ");
ArrayList<Character> A = new ArrayList<Character>();
ArrayList<Character> B = new ArrayList<Character>();
for(int i = 0; i < boxs[0].length(); i++) {
A.add(boxs[0].charAt(i));
}
for(int i = 0; i < boxs[1].length(); i++) {
B.add(boxs[1].charAt(i));
}
for(int i = 0; i < B.size(); i++) {
if(A.contains(B.get(i))) {
A.remove(A.get(A.indexOf(B.get(i))));
B.remove(i);
i--;
}
}
if(B.size() == 0) {
System.out.println("Yes");
} else {
System.out.println("No");
}
A = null;
B = null;
}
}
#include<stdio.h>
#include<string.h>
#define N 10001
int main()
{
int a[26],b[26];
char A[N],B[N];
while(scanf("%s %s",A,B)!=-1)
{
int i,j,flag=1;
int len_A=strlen(A);
int len_B=strlen(B);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=0;i<len_A;i++)
{
j=A[i]-'A';
a[j]++;
}
for(i=0;i<len_B;i++)
{
j=B[i]-'A';
b[j]++;
}
for(i=0;i<26;i++)
{
//printf("%d %d\n",a[i],b[i]);
if((a[i]==0&&b[i]>0)||b[i]>a[i])
{
flag=0;
break;
}
}
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return 0;
} 思路: map的应用。
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
string A, B;
while(cin >> A >> B)
{
map<char, int> AA, BB;
for (int i = 0; i < A.size(); i++)
{
AA[A[i]]++;
}
for (int i = 0; i < B.size(); i++)
{
BB[B[i]]++;
}
for (int i = 'A'; i <= 'Z'; i++)
{
if (BB[i] > AA[i])
{
cout << "No" << endl;
break;
}
if (i == 'Z')
{
cout << "Yes" << endl;
}
}
}
}
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
string str, res;
while (cin >> str >> res)
{
bool sta = true;
map<char, int> strdata, resdata;
for (auto c : str)
strdata[c]++;
for (auto c : res)
resdata[c]++;
for (map<char, int>::iterator it = resdata.begin(); it != resdata.end(); it++)
if (strdata[it->first] < it->second)
{
sta = false;
break;
}
if (true == sta)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
whileTrue:try:A, B = raw_input().split()iflen(A) < len(B):print "No"continuealpha = [0] * 26fori in A:alpha[ord(i) - 65] += 1flag = Truefori in B:alpha[ord(i) - 65] -= 1ifalpha[ord(i) - 65] < 0:flag = Falsebreakprint "Yes"ifflag else"No"except:break
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while (in.hasNext())
{
boolean contain = true;
StringBuffer input = new StringBuffer(in.next());
char[] find = in.next().toCharArray();
for (char c : find)
{
int index = input.indexOf(String.valueOf(c));
if (index != -1)
input.deleteCharAt(index);
else
{
System.out.println("No");
contain = false;
break;
}
}
if (contain)
System.out.println("Yes");
}
}
} #include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){
string a, b;
while(cin >> a >> b){
map<char, int> ma, mb;
for(auto e : a){
++ma[e];
}
for(auto e : b){
++mb[e];
}
bool flag = true;
//for(map<char, int>::iterator it = mb.begin(); it != mb.end(); ++it){
//if(ma[it->first] < it->second){
for(auto e : mb){
if(ma[e.first] < e.second){
flag = !flag;
break;
}
}
if(flag){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
return 0;
} #include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
string str1, str2;
while(cin >> str1 >> str2)
{
unordered_map<int, int> hash1, hash2;
for(auto x : str1) hash1[x]++;
for(auto y : str2) hash2[y]++;
int flag = 1;
for(auto y : str2)
if(!hash1.count(y) || hash1[y] < hash2[y])
{
cout << "No" << endl;
flag = 0;
break;
}
if(flag) cout << "Yes" << endl;
}
return 0;
} #include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
int main() {
string str1, str2;
while (cin >> str1 >> str2) {
bool flag = true;
unordered_map<char, int> mp1, mp2;
for (auto& e : str1) mp1[e]++;
for (auto& e : str2) mp2[e]++;
for (auto& e : mp2) {
auto it = mp1.find(e.first);
if (it != mp1.end()) {
if (e.second > mp1[e.first]) {
flag = false;
}
} else {
flag = false;
}
}
if(flag == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
// 64 位输出请用 printf("%lld") import java.util.HashMap;
import java.util.Scanner;
public class Main {
private static boolean basket(String str1, String str2) {
if (str1.length() == 0) {
return false;
}
if (str2.length() == 0) {
return true;
}
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < str1.length(); i++) {
if (map.containsKey(str1.charAt(i))) {
map.put(str1.charAt(i), map.get(str1.charAt(i)) + 1);
} else {
map.put(str1.charAt(i), 1);
}
}
for (int i = 0; i < str2.length(); i++) {
if (map.containsKey(str2.charAt(i))) {
map.put(str2.charAt(i), map.get(str2.charAt(i)) - 1);
if (map.get(str2.charAt(i)) < 0) {
return false;
}
} else {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
String str = sc.nextLine();
String[] strings = str.split(" ");
if (basket(strings[0], strings[1])) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
}
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String boxA = in.next();
String boxB = in.next();
Map<Character,Integer> mapA = new HashMap<>();
for(int i = 0;i < boxA.length();i++){
char a = boxA.charAt(i);
if(mapA.containsKey(a)){
mapA.replace(a,mapA.get(a) + 1);
}else {
mapA.put(a,1);
}
}
Map<Character,Integer> mapB = new HashMap<>();
for(int i = 0;i < boxB.length();i++){
char a = boxB.charAt(i);
if(mapB.containsKey(a)){
mapB.replace(a,mapB.get(a) + 1);
}else {
mapB.put(a,1);
}
}
boolean flag = true;
for(int i = 0;i < boxB.length();i++){
char a = boxB.charAt(i);
if(!(mapA.containsKey(a) && mapA.get(a) >= mapB.get(a))){
flag = false;
}
}
System.out.println(flag == true ? "Yes" : "No");
}
}
} import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String a = sc.next();
String b = sc.next();
char[] aa = a.toCharArray();
char[] bb = b.toCharArray();
Map<Character,Integer> mapA = new HashMap<>();
Map<Character,Integer> mapB = new HashMap<>();
for(char e : aa){
if(!mapA.containsKey(e)){
mapA.put(e,1);
}else{
mapA.put(e,mapA.get(e) + 1);
}
}
for(char e : bb){
if(!mapB.containsKey(e)){
mapB.put(e,1);
}else{
mapB.put(e,mapB.get(e) + 1);
}
}
boolean flg = true;
for(char e : bb){
if(!mapA.containsKey(e) || mapA.get(e) < mapB.get(e)){
flg = false;
break;
}
}
if(flg){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
} import java.util.*;
public class Main{
public static void main(String[]args){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
String str1=in.next();
String str2=in.next();
boolean ret=find(str1,str2);
if(ret){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}
public static boolean find(String str1,String str2){
int[]arr=new int[26];
//定义容量为26的数组存储数字
//遍历字符串1,存储对应的字母数量 ,比如A对应的就是数组0号元素
for(int i=0;i<str1.length();i++){
char ch=str1.charAt(i);
int temp=(int)(ch-65);
arr[temp]++;
}
//遍历字符串2,找到对应字母下标,进行相减
for(int i=0;i<str2.length();i++){
char ch=str2.charAt(i);
int temp=(int)(ch-65);
//对应下标容量为0,说明A盒子没有,或者A盒子里的数量小于B盒子的数量
//返回false;
if(arr[temp]==0){
return false;
}
arr[temp]--;
}
//结束字符串2的遍历,没有返回false。说明满足条件
return true;
}
}
import java.util.*;
public class Main{
public static String IsOKContais(String str){
String[] ret = str.split(" ");
Map<Character,Integer> map = new HashMap<>();//A
Map<Character,Integer> map0 = new HashMap<>();//B
for(int i = 0;i < ret[0].length();i++){
if(!map.containsKey(ret[0].charAt(i))){
map.put(ret[0].charAt(i),1);
}else{
map.put(ret[0].charAt(i),map.get(ret[0].charAt(i)) + 1);
}
}
for(int i = 0;i < ret[1].length();i++){
if(!map0.containsKey(ret[1].charAt(i))){
map0.put(ret[1].charAt(i),1);
}else{
map0.put(ret[1].charAt(i),map0.get(ret[1].charAt(i)) + 1);
}
}
for(Map.Entry<Character,Integer> entry:map0.entrySet()){
Character Key = entry.getKey();
Integer Value = entry.getValue();
if(map.containsKey(Key)){
if(map.get(Key) < Value){
return "No";//包含但数目不对
}
}else{
return "No";//不包含
}
}
return "Yes";
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String str = scan.nextLine();
System.out.println(IsOKContais(str));
}
}
} import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String str = scanner.nextLine();
String[] tem = str.split(" ");
HashMap<Character, Integer> A = new HashMap<>();
HashMap<Character, Integer> B = new HashMap<>();
boolean res = true;
for (int i = 0; i < tem[0].length(); i++) {
if (!A.containsKey(tem[0].charAt(i))) {
A.put(tem[0].charAt(i), 1);
} else {
A.put(tem[0].charAt(i), A.get(tem[0].charAt(i)) + 1);
}
}
for (int i = 0; i < tem[1].length(); i++) {
if (!B.containsKey(tem[1].charAt(i))) {
B.put(tem[1].charAt(i), 1);
} else {
B.put(tem[1].charAt(i), B.get(tem[1].charAt(i)) + 1);
}
}
Iterator<Character> iterator = B.keySet().iterator();
while (iterator.hasNext()) {
Character key = iterator.next();
if (A.containsKey(key) && A.get(key) >= B.get(key)) {
continue;
}else {
res = false;
break;
}
}
if (res) System.out.println("Yes");
if (!res) System.out.println("No");
}
}
} #include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string s1,s2;
int table[27];
memset(table,0,sizeof(table));
while(cin>>s1>>s2)
{
int len1=s1.size();
int len2=s2.size();
for(int i=0; i<len1; i++)
{
table[s1[i]-'A']++;
}
int flag=1;
for(int i=0; i<len2; i++)
{
if(--table[s2[i]-'A']<0)
{
flag=0;
break;
}
}
if(flag)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
} import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while (sc.hasNext()){
Map<Character,Integer>map=new HashMap<>();
String[]str=new String[2];
str=sc.nextLine().split(" ");
/*System.out.println(str[0]);
System.out.println(str[1]);*/
String searh = searh(str, map);
System.out.println(searh);
}
}
private static String searh(String[] str,Map<Character,Integer> map) {
for (int i = 0; i <str[0].length() ; i++) {
if (map.containsKey(str[0].charAt(i))){
map.put(str[0].charAt(i),map.get(str[0].charAt(i))+1);
}else {
map.put(str[0].charAt(i),1);
}
}
for (int i = 0; i <str[1].length() ; i++) {
if (map.containsKey(str[1].charAt(i))){
map.put(str[1].charAt(i),map.get(str[1].charAt(i))-1);
}else {
return "No";
}
}
for (int i = 0; i <str[0].length() ; i++) {
if (map.get(str[0].charAt(i))<0){
// System.out.println(map.get(str[0].charAt(i)));
return "No";
}
}
return "Yes";
}
} 笨比解法 我摊牌了 我是笨比😥