描述
判断短字符串S中的所有字符是否在长字符串T中全部出现。
请注意本题有多组样例输入。
数据范围:1\le len(S),len(T)\le200\1≤len(S),len(T)≤200
进阶:时间复杂度:O(n)\O(n) ,空间复杂度:O(n)\O(n)
输入描述:
输入两个字符串。第一个为短字符串,第二个为长字符串。两个字符串均由小写字母组成。
输出描述:
如果短字符串的所有字符均在长字符串中出现过,则输出字符串"true"。否则输出字符串"false"。
示例1
输入:
bc abc复制输出:
true复制说明:
其中abc含有bc,输出"true"
package org.example.simple;
import java.util.Scanner;
public class Hj56 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int count = 0;
if (n >= 1 && n<= 5 * 100000) {
for (int i = n; i > 0; i--) {
if(slove(i)){
count++;
}
}
System.out.println(count);
}
}
}
public static boolean slove(int n) {
int sum = 0;
for (int i = n - 1; i > 0; i--) {
if (n % i == 0) {
sum += i;
}
}
if(sum == n){
return true;
}else {
return false;
}
}
}