PAT-1152(Google Recruitment)字符串+素数
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)字符串+素数的更多相关文章
- PAT 1152 Google Recruitment
1152 Google Recruitment (20 分) In July 2004, Google posted on a giant billboard along Highway 101 ...
- PAT甲级:1152 Google Recruitment (20分)
PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...
- PAT甲级——1152.Google Recruitment (20分)
1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...
- pat甲级 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- 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 ...
- 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 ...
- 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...
- 1152 Google Recruitment
题干前半略. Input Specification: Each input file contains one test case. Each case first gives in a line ...
- PAT_A1152#Google Recruitment
Source: PAT A1152 Google Recruitment (20 分) Description: In July 2004, Google posted on a giant bill ...
随机推荐
- poj 1410 (没做出来,记得闲着没事看看这道题)
听说这道题是个大大的坑题 结果wa了十多发,,,,还是没找到原因 #include<cstdio> #include<cmath> #include<algorithm& ...
- HDU - 6287 口算训练 二分+质因数分解
小Q非常喜欢数学,但是他的口算能力非常弱.因此他找到了小T,给了小T一个长度为nn的正整数序列a1,a2,...,ana1,a2,...,an,要求小T抛出mm个问题以训练他的口算能力.每个问题给出三 ...
- Codeforces Round #656 (Div. 3) D. a-Good String (DFS)
题意:有一个长度为\(n=2^k\)的字符串,对于某个字符\(c\),我们定义他是一个\(c-good\),如果: 1.\(len=1\),并且\(s[1]=c\). 2.\(len>1 ...
- meterpreter php payload && windows payload 学习
一 情景 本地kali linux 192.168.1.2 目标 windows NT 服务器192.168.1.4 目的是获取shell 二 过程 首先在linux建立终端 ,msfconsole ...
- printf,sprintf,fprintf的区别与联系
在写代码过程中总会遇到printf和sprintf,既然这两个都遇到了,那么不妨再加一个fprintf吧. 他们三个都是将格式化字符串输出,区别就是他们输出的目标不一样. (1).printf,是把格 ...
- HDU 6704 K-th occurrence(主席树 + RMQ + 后缀数组)题解
题意: 给一个串\(S\),\(length\leq 1e5\),\(Q\leq1e5\)个询问,每次询问输出和\(S_lS_{l+1}\dots S_r\)长得一模一样的第\(k\)个子串的开头位置 ...
- LeetCode 数组分割
LeetCode 数组分割 LeetCode 数组怎么分割可以得到左右最大值的差值的最大 https://www.nowcoder.com/study/live/489/1/1 左右最值最大差 htt ...
- Awesome GitHub Topics
Awesome GitHub Topics freeCodeCamp https://github.com/topics/javascript?o=desc&s=stars https://g ...
- ES6 Class vs ES5 constructor function All In One
ES6 Class vs ES5 constructor function All In One ES6 类 vs ES5 构造函数 https://developer.mozilla.org/en- ...
- Web 全栈开发 Redis 面试题
Web 全栈开发 Redis 面试题 Redis 大 key 问题 https://www.cnblogs.com/xgqfrms/p/13601959.html Redis 数据结构 Redis 初 ...