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. 【uva 11082】Matrix Decompressing(图论--网络流最大流 Dinic+拆点二分图匹配)

    题意:有一个N行M列的正整数矩阵,输入N个前1~N行所有元素之和,以及M个前1~M列所有元素之和.要求找一个满足这些条件,并且矩阵中的元素都是1~20之间的正整数的矩阵.输入保证有解,而且1≤N,M≤ ...

  2. hdu3555 Bomb(要49)

    Problem Description The counter-terrorists found a time bomb in the dust. But this time the terroris ...

  3. JavaScript——六

    magin和padding的区别:https://www.cnblogs.com/zxnn/p/8186225.html magin:兄弟之间的 padding:父子关系 body和网页边框左右距离上 ...

  4. k8s-3-容器云监控系统

    apollo小结 课程目录 一.容器云监控prometheus概述 https://prometheus.io/docs/introduction/overview/ #官方文档 https://gi ...

  5. Operating System:管程相关概念

    管程 (Moniters,也称为监视器)一.管程的概念是一种程序结构,结构内的多个子程序(对象或模块)形成的多个工作线程互斥访问共享资源.这些共享资源一般是硬件设备或一群变量.管程实现了在一个时间点, ...

  6. VMware ESXi 开启嵌套虚拟化

    VMware ESXi 默认不支持嵌套虚拟化功能,需要修改相关配置文件才能支持. 1.Esxi主机开启ssh,修改 /etc/vmware/config 配置文件,在配置文件后面加入如下配置:vhv. ...

  7. 1.nginx安装和基本配置

    作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-07-10 20:56:10 星期三 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...

  8. python to exe

    使用pyinstaller 打包 文件结构如下 命令行cd 进入 project文件夹 ,然后 命令 pyinstaller -F main.py 即可打包文件为一个完整的exe.(不含DLL等)

  9. ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

    cmd mysql -h localhost -u root -p r然后报错 ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost ...

  10. HDU - 4462 Scaring the Birds

    It's harvest season now! Farmer John plants a lot of corn. There are many birds living around his co ...