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

字符串字符匹配

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String a, b;
        try {
            a = in.readLine();
            b = in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        char[] charAyShort = a.toCharArray();
        char[] charAyLong = b.toCharArray();
        short i = 0, ls = (short) charAyShort.length, ll = (short) charAyLong.length;
        int[] as = new int[123];
        int[] al = new int[123];
        boolean contain = true;
        while (i < ls) {
            as[charAyShort[i]] = 1;
            i++;
        }
        i = 0;
        while (i < ll) {
            al[charAyLong[i]] = 1;
            i++;
        }
        i = 0;
        while (i < 123) {
            if (as[i] == 1 && al[i] == 0) {
                contain = false;
                break;
            }
            i++;
        }
        System.out.print(contain);
    }
}

全部评论

相关推荐

09-13 18:00
武汉大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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