题解 | #字符串字符匹配#,越简单的题越容易粗心大意

字符串字符匹配

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String a = in.next();
            String str = in.next();
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < a.length(); i++) {
                for (int j = 0; j < str.length(); j++) {
                    if (a.charAt(i) == str.charAt(j)){
                        builder.append(1);
                        break;
                    }
                }
            }
        
            System.out.println(builder.length() == a.length());
        }
    }
}

全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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