Google Recruitment

PAT-1152

  • 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况。
/**
* @Author WaleGarrett
* @Date 2020/9/18 21:14
*/
import java.io.*;
import java.util.*;
public class PAT_1152 {
public static boolean isPrime(int n){
int qn=(int)Math.sqrt(n+1);
for(int i=2;i<=qn;i++){
if(n%i==0){
return false;
}
}
return true;
}
public static void main(String[] args) {
int l,k;
Scanner cin=new Scanner(System.in);
l=cin.nextInt();
k=cin.nextInt();
cin.nextLine();
String s=cin.nextLine();
if(k<=0){
System.out.println("404");
return;
}
// System.out.println(s);
boolean flag=false;
for(int i=0;i<=s.length()-k;i++){
int num=0;
for(int j=i;j<i+k;j++){
char ch=s.charAt(j);
int a=ch-'0';
num=num*10+a;
}
if(num<2)
continue;
if(isPrime(num)){
// System.out.println(num);
System.out.println(s.substring(i,i+k));
flag=true;
break;
}
}
if(!flag)
System.out.println("404");
}
}

PAT-1152(Google Recruitment)字符串+素数的更多相关文章

  1. PAT 1152 Google Recruitment

    1152 Google Recruitment (20 分)   In July 2004, Google posted on a giant billboard along Highway 101 ...

  2. PAT甲级:1152 Google Recruitment (20分)

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  3. PAT甲级——1152.Google Recruitment (20分)

    1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...

  4. pat甲级 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  5. PAT Advanced 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  6. PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  7. 1152 Google Recruitment (20 分)

    In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...

  8. 1152 Google Recruitment

    题干前半略. Input Specification: Each input file contains one test case. Each case first gives in a line ...

  9. PAT_A1152#Google Recruitment

    Source: PAT A1152 Google Recruitment (20 分) Description: In July 2004, Google posted on a giant bill ...

随机推荐

  1. Codeforces Global Round 8 D. AND, OR and square sum(位运算)

    题目链接:https://codeforces.com/contest/1368/problem/D 题意 给出一个大小为 $n$ 的数组 $a$,每次可以选两个下标不同的元素,一个赋为二者相与的值, ...

  2. poj 2566 Bound Found 尺取法

    一.首先介绍一下什么叫尺取 过程大致分为四步: 1.初始化左右端点,即先找到一个满足条件的序列. 2.在满足条件的基础上不断扩大右端点. 3.如果第二步无法满足条件则到第四步,否则更新结果. 4.扩大 ...

  3. Gym 102263 ArabellaCPC 2019 J - Thanos Power (DP,数学)

    题意:有一个整数\(n\),每次可以对加\(10^x\)或减\(10^x\),问最少操作多少次能得到\(n\). 题解:对于某一位上的数,我们可以从\(0\)加几次得到,或者从前一位减几次得到.所以对 ...

  4. servlet相关知识点

    一.servlet的生命周期 Servlet(Sever Applet),全称是Java Servlet,是用java编写的服务器程序.Servlet是指任何实现了这个Servlet接口的类. ser ...

  5. vue 单文件组件最佳实践

    vue 单文件组件最佳实践 生命周期 template <template> <section> <h1>vue single file components te ...

  6. Node.js Spider

    Node.js Spider How To Write a Spider using JavaScript, in order to auto download some svg images for ...

  7. Flutter & release an iOS app

    Flutter & release an iOS app https://flutter.dev/docs/deployment/ios .ipa https://en.wikipedia.o ...

  8. Raspberry Pi & Raspberry Pi 4

    Raspberry Pi & Raspberry Pi 4 pdf https://www.raspberrypi.org/magpi/issues/beginners-guide-2nd-e ...

  9. asm align 对齐数据

    最大成员dword data: dd 1 db 2 align 4 dw 3 000E0010 - 01 00 00 00 000E0014 - 02 00 00 00 000E0018 - 03 0 ...

  10. c++ 获取当前程序的主模块句柄

    char text[2014]; GetModuleBaseNameA(GetCurrentProcess(), 0, text, 1024); HMODULE hModule = GetModule ...