我们定义字符串包含关系:字符串 A=abc ,字符串 B=ab ,字符串 C=ac ,则说 A 包含 B , A 和 C 没有包含关系。
数据范围:输入的字符串长度满足
A包含B,B包含A都行,都输出1
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String str1=sc.next(); String str2=sc.next(); if(str1.contains(str2)||str2.contains(str1))//互相包含 { System.out.println(1); } else { System.out.println(0); } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s1 = sc.next(); String s2 = sc.next(); int res = (s1.contains(s2) || s2.contains(s1)) ? 1 : 0; System.out.println(res); } } }用contain只需要两行
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { String str1 = scanner.next(); String str2 = scanner.next(); System.out.println((str1.contains(str2) || str2.contains(str1)) ? 1 : 0); } } }