题解 | #字符串字符匹配#

字符串字符匹配

https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93

# !/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'tianyi'
__date__ = '2024/3/23 20:04 '
__file__ = 'HW_HJ81.py'
import sys
# 1. 读取输入
need_match = ""
n = 0
for i in sys.stdin:
    # 2. 按空格分割
    n+=1
    total = 0
    if n%2 == 0:
        String1 = i.rstrip()
        for i in need_match:
            if i not in String1:
                print("false")
                break
            else:
                total += 1
        if total == len(need_match):
            print("true")
    else:
        need_match = i.rstrip()

字符串可以遍历,可以使用 not in逻辑。

全部评论

相关推荐

07-07 12:47
门头沟学院 Java
码农索隆:竟然还真有卡体检报告的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务