首页 > 试题广场 >

字符串字符匹配

[编程题]字符串字符匹配
  • 热度指数:161875 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
判断短字符串S中的所有字符是否在长字符串T中全部出现。
请注意本题有多组样例输入。
数据范围:
进阶:时间复杂度:,空间复杂度:

输入描述:

输入两个字符串。第一个为短字符串,第二个为长字符串。两个字符串均由小写字母组成。



输出描述:

如果短字符串的所有字符均在长字符串中出现过,则输出字符串"true"。否则输出字符串"false"。

示例1

输入

bc
abc

输出

true

说明

其中abc含有bc,输出"true"
 
头像 BSF
发表于 2021-10-18 19:26:06
while True: try: S, T = input(), input() if set(S) & set(T) == set(S): print('true') else: pri 展开全文
头像 小陆要懂云
发表于 2021-08-19 10:16:37
#include <iostream> #include <string> #include <unordered_set> using namespace std; int main(){ string shortS,longS; bool re 展开全文
头像 空中转体一周半
发表于 2022-05-03 19:35:58
用Set走捷径!把短字符串的字符加入到Set中,把长字符的字符从Set中剔除,如果最后Set为空,则满足条件。 public class Main { public static void main(String[] args) { Scanner in = new Scan 展开全文
头像 派仔
发表于 2020-08-11 17:43:00
Set 轻松解决 import java.util.*; public class Main { public Main() { } public boolean isAllCharExist(String pShortString, String pLongStrin 展开全文
头像 牛客8008419号
发表于 2021-12-16 01:03:33
```while True: try: str1 = list(input()) str2 = list(input()) for i in str1: if i not in str2: 展开全文
头像 qybkb24
发表于 2021-11-17 20:03:01
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc 展开全文
头像 加油嘞
发表于 2022-03-13 22:41:24
#include<stdio.h> #include<string.h> int main(){ char data[200]; char str[200]; int num,len,i,j; while(scanf("%s",&dat 展开全文
头像 KrazyPhish
发表于 2022-04-12 22:48:45
Array.every()用于对数组每个值遍历,且按回调函数的规则返回结果true/false,结果条件必须是数组中的所有值都满足,则该方法返回值才为true 与之相反的是Array.some()方法,同样遍历数组,但只需有一个满足条件即可返回true let str = readline().sp 展开全文
头像 牛客374676145号
发表于 2022-03-05 20:37:56
while 1: try: s,l = set(input()), set(input()) if s & l == s: print('true') else: print('false') except: b 展开全文
头像 阿亮阿亮来了呀
发表于 2022-03-01 13:35:15
/** * 解题思路 * 1.循环接收输入的字符串 * 2.将短字符串截成数组 * 3.判断长字符串中是否包含短字符串的每个字符,全部包含返回true,只要有一个不包含返回false */ public static void strCont 展开全文