吉普特 笔试题

  • 题目一:

  • 题目描述:给与多个字符串,判断另一个字符串中是否包含如上字符串之一

输入描述: 第一行为数字×( X <=10000),表示需要匹配的字符串数量,接下来 X 行字符串为需要匹配的字符串,每个字符串长度不超过20。 接着一行为数宇 Y ( Y <=10000),表示需要检测的字符串数量,接下来 Y 行字符串为需要检测的字符串,每个字符串长度不超过1000。 所有字符均为小写字母

输出描述: 如果匹配结果为包含如上字符串之一,则输出 yes ,否则输出 no

示例1输入输出示例仅供调试,后台判题数据一般不包含示例

输入

3

abc

abd

acd 

4

abcd

dcba

bacd

sajdksaj

输出

yes

no

yes

no

解题代码如下:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        String[] source = new String[x];

        for (int i = 0; i < x; i++) {
            source[i] = scanner.next();

        }
        int y = scanner.nextInt();
        String[] test = new String[y];
        for (int i = 0; i < y ; i++) {
            test[i] = scanner.next();


        }
        boolean tarres =false;
        for (int i = 0; i < y; i++) {
            for (int j = 0; j < x; j++) {
                tarres = tarres || s1(test[i],source[j]);
            }
            System.out.println(tarres?"yes":"no");
            tarres =false;
        }

    }

    public static boolean s1(String s, String t) {
        boolean isfind =false;

        for (int i = 0; i < s.length() - t.length() + 1; i++) {
            if (s.charAt(i) == t.charAt(0)) {
                int jc = 0;
                for (int j = 0; j < t.length(); j++) {
                    if (s.charAt(i + j) != t.charAt(j)) {
                        break;
                    }
                    jc = j;
                }
                if (jc == t.length() - 1) {

                    isfind = true;
                }
            }
        }
        return isfind;
    }
}

题目二:

  • 题目描述 给定一个数列,其中可能有正数也可能有负数,我们的任务是找出其中连续的一个子数列(不允许空序列,使它们的和尽可能小。 输入描述: 第一行:一个数字 N , N <1000 第二行: N 个数字,每个数字 x ,-10000く x く10000 输出描述: 子数列最小和

示例1输入输出示例仅供调试,后台判题数据一般不包含示例 输入

8

-2  6  -1  -5  4  -7  -2  3

输出

-11

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] source = new int[n+1];
        for (int i = 0; i < n; i++) {
            source[i] = scanner.nextInt();
        }
        int res = 0;
        int dp_0 = 0;
        int dp_1 =res;
        for (int i = 0; i < n; i++) {
            dp_1 = Math.min(source[i],source[i]+dp_0);
            dp_0 =dp_1;
            res = Math.min(res,dp_1);

        }
        System.out.println(res);
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值