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. gym101002K. Inversions (FFT)

    题意:给定一个仅含有AB的字母串 如果i有一个B j有一个A 且j>i 会对F(j-i)产生贡献 求出所有发Fi 题解:好像是很裸的FFT B的分布可以看作一个多项式 同理A也可以 然后把B的位 ...

  2. 【uva 12174】Shuffle(算法效率--滑动窗口)

    题意:假设一种音乐播放器有一个乱序的功能,设定每播放S首歌为一个周期,随机播放编号为1~S的歌曲.现在给一个长度为N的部分播放记录,请统计下次随机排序所发生的时间的可能性种数.(1≤S,N≤10000 ...

  3. python爬取酷我音乐

    我去!!!我之后一定按照搜索方式下载歌曲~~~~~~~~~ 1.首先打开我们本次主讲链接:http://www.kuwo.cn/  2.刚开始我就随便点了一个地方,然后开始在后台找歌曲的链接地址.但是 ...

  4. Codeforces Round #494 (Div. 3) D. Coins and Queries (贪心,数学)

    题意:给你一组全是\(2^d\ (d\ge0)\)的数,询问q次,每次询问一个数,问这个数是否能够由原数组中的数相加得到,如果能,输出最少用多少个数,否则输出\(-1\). 题解:首先贪心得出结论:如 ...

  5. 2019 ICPC Asia Taipei-Hsinchu Regional Problem K Length of Bundle Rope (贪心,优先队列)

    题意:有\(n\)堆物品,每次可以将两堆捆成一堆,新堆长度等于两个之和,每次消耗两个堆长度之和的长度,求最小消耗使所有物品捆成一堆. 题解:贪心的话,每次选两个长度最小的来捆,这样的消耗一定是最小的, ...

  6. XV6学习(16)Lab net: Network stack

    最后一个实验了,代码在Github上. 这一个实验其实挺简单的,就是要实现网卡的e1000_transmit和e1000_recv函数.不过看以前的实验好像还要实现上层socket相关的代码,今年就只 ...

  7. TCP 连接

    面试题传送 TCP 报文格式 此处介绍建立或者断开TCP连接时,需要了解的TCP报文段首部字段含义: 序列号 seq:占4个字节(32位),用来标记数据段的顺序,TCP把连接中发送的所有数据字节都编上 ...

  8. 接口测试框架Requests

    目录 Requests Requests安装 Requests常见接口请求方法构造 请求目标构造 header构造 cookie 构造请求体 Get Query请求 Form请求参数 JSON请求体构 ...

  9. Lightoj 1038 - Race to 1 Again【期望+dp】

    题目:戳这里 题意:一个数字n不断迭代地除以自身的因子得到1.求这个过程中操作除法次数的期望. 解题思路: 求概率基本都是从一个最基础的状态开始延伸推出公式,得出答案.因为每个数都有个共同的最终状态1 ...

  10. 翻译:《实用的Python编程》01_02_Hello_world

    目录 | 上一节 (1.1 Python) | 下一节 (1.3 数字) 1.2 第一个程序 本节讨论有关如何创建一个程序.运行解释器和调试的基础知识. 运行 Python Python 程序始终在解 ...