描述 | |
---|---|
知识点 | 字符串,循环,指针 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入两个字符串。第一个为短字符,第二个为长字符。 |
输出 | 返回值: true - 表示短字符串中所有字符均在长字符串中出现 false- 表示短字符串中有字符在长字符串中没有出现
|
样例输入 | bc abc |
样例输出 | true |
/*题目比较简单,但是题目要求没有怎么说清楚
* 只要短字符串的所有字符都在长字符串中出现就行,没有顺序要求
* 例如:abc bca 结果为true
* aaa abc 结果为true
* */
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] shortString = sc.nextLine().split("");
String longString = sc.nextLine();
sc.close();
int length = 0;
/*定义length,遍历短字符串的每一个元素,当有一个元素在长字符串中出现,
则length++,如果最后length等于短字符串长度,则说明所有字符都在长字符串中出现*/
for (int i = 0; i < shortString.length; i++) {
if(longString.contains(shortString[i]))
length++;
}
if (length == shortString.length)
System.out.println("true");
else
System.out.println("false");
}
}