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. CodeForces833 B. The Bakery 线段树维护dp

    题目链接:https://vjudge.net/problem/CodeForces-833B 题意:给长度为n的数组a,和一个整数k要求把数组分成连续的k段,每段的权值是该段中不同数的个数,输出最大 ...

  2. Codeforces Round #672 (Div. 2) D. Rescue Nibel! (思维,组合数)

    题意:给你\(n\)个区间,从这\(n\)区间中选\(k\)个区间出来,要求这\(k\)个区间都要相交.问共有多少种情况. 题解:如果\(k\)个区间都要相交,最左边的区间和最右边的区间必须要相交,即 ...

  3. python爬虫下载小视频和小说(基础)

    下载视频: 1 from bs4 import BeautifulSoup 2 import requests 3 import re 4 import urllib 5 6 7 def callba ...

  4. Codeforces Round #654 (Div. 2) C. A Cookie for You (思维)

    题意:有\(a\)个蛋糕,\(b\)个巧克力,第一类人有\(n\)个,总是吃多的东西(若\(a>b\),吃蛋糕,否则吃巧克力),第二类人有\(m\)个,总是吃少的,可以随便调整这两类人吃的顺序, ...

  5. 【史上最全】Hadoop 核心 - HDFS 分布式文件系统详解(上万字建议收藏)

    1. HDFS概述 Hadoop 分布式系统框架中,首要的基础功能就是文件系统,在 Hadoop 中使用 FileSystem 这个抽象类来表示我们的文件系统,这个抽象类下面有很多子实现类,究竟使用哪 ...

  6. Django用户注册、登录

    一.用户注册 1 ''' 2 注册的表单模型 3 forms.py 的例子 4 ''' 5 6 from django import forms #表单功能 7 from django.contrib ...

  7. LINUX - pthread_mutex_lock

    原文链接:https://www.cnblogs.com/fengbohello/p/7571722.html 互斥的概念 在多线程编程中,引入了对象互斥锁的概念,来保证共享数据操作的完整性. 每个对 ...

  8. docker镜像拉取、运行、删除

    1.拉取hello-world镜像并运行 docker pull hello-world 拉取hello-world镜像Using default tag: latestlatest: Pulling ...

  9. HTML form All In One

    HTML form All In One action + method onsubmit, submit event action + method <form action="&q ...

  10. HTML Custom Elements & valid name

    HTML Custom Elements & valid name valid custom element name https://html.spec.whatwg.org/multipa ...