华为机试---字符串匹配

这是一道华为公司的机试题目,要求实现一个函数,判断一个短字符串中的所有字符是否都包含在长字符串中。函数原型为boolIsAllCharExist,接收两个参数,分别代表短字符串和长字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

题目标题:

判断短字符串中的所有字符是否在长字符串中全部出现

详细描述:

接口说明

原型:

boolIsAllCharExist(char* pShortString,char* pLongString);

输入参数:

    char* pShortString:短字符串

    char* pLongString:长字符串 


输入描述:

输入两个字符串。第一个为短字符,第二个为长字符。

输出描述:

返回值:

输入例子:
bc
abc
输出例子:
true
import java.util.ArrayList;

import java.util.List;
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
String short_string = scan.nextLine();
String long_string = scan.nextLine();
boolIsAllCharExist(short_string , long_string);
}//endwhile
scan.close();
}
private static void boolIsAllCharExist(String short_string , String long_string){
List<Character> short_list = new ArrayList<Character>();
List<Character> long_list = new ArrayList<Character>();
int short_length = short_string.length();
int long_length = long_string.length();
for(int i = 0 ; i < short_length ; i++){
short_list.add(short_string.charAt(i));
}
for(int i = 0 ; i < long_length ; i++){
long_list.add(long_string.charAt(i));
}
char temp_ch = '*';
int count = 0;
for(int i = 0 ; i < short_length ; i++){
temp_ch = short_list.get(i);
if(long_list.contains(temp_ch)){
count++;
}
}
if(count == short_length){
System.out.println(true);
}else{
System.out.println(false);
}
}
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值