1152 Google Recruitment
题干前半略。
Input Specification:
Each input file contains one test case. Each case first gives in a line two positive integers: L (≤ 1,000) and K (< 10), which are the numbers of digits of the given number and the prime to be found, respectively. Then the L-digit number N is given in the next line.
Output Specification:
For each test case, print in a line the first K-digit prime in consecutive digits of N. If such a number does not exist, output 404 instead. Note: the leading zeroes must also be counted as part of the K digits. For example, to find the 4-digit prime in 200236, 0023 is a solution. However the first digit 2 must not be treated as a solution 0002 since the leading zeroes are not in the original number.
Sample Input 1:
20 5
23654987725541023819
Sample Output 1:
49877
Sample Input 2:
10 3
2468024680
Sample Output 2:
404
#include<stdio.h>
#include<vector>
#include<string>
#include<iostream>
#include<math.h>
using namespace std; bool isprime(int n)
{ if(n==1||n==0) return false;
for(int i=2;i<=(int)sqrt(n);i++)
{
if(n%i==0) return false;
}
return true;
}
bool flag;
int main()
{
int num;
int primenum;
scanf("%d",&num);
scanf("%d",&primenum);
string seq;
cin>>seq;
while(seq[0]=='0') seq.erase(seq.begin());
int i;
for(i=0;i<num;i++)
{
int start=i;
char temp[20];
int t=0;
if(num-i<primenum) break;
for(int j=i;j<i+primenum;j++)
{
temp[t++]=seq[j];
}
int newnum;
sscanf(temp,"%d",&newnum);
temp[t]='\0';
if(isprime(newnum))
{
cout<<temp;
flag=true;
return 0;
}
}
if(i==num-primenum+1) printf("404\n");
}
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分)
1152 Google Recruitment (20分) In July 2004, Google posted on a giant billboard along Highway 101 in ...
- 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 分)
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 ...
- 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 ...
- PAT_A1152#Google Recruitment
Source: PAT A1152 Google Recruitment (20 分) Description: In July 2004, Google posted on a giant bill ...
- PAT-1152(Google Recruitment)字符串+素数
Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况. /** * @Author WaleGarrett * @Date ...
随机推荐
- Thread线程控制之sleep、join、setDaemon方法的用处
Thread线程控制之sleep.join.setDaemon方法的用处 1. sleep方法 public static void sleep(long millis) throws Interru ...
- #2使用html+css+js制作网站教程 测试
#2使用html+css+js制作网站教程 测试 本系列链接 1 测试 1.1 运行 1.2 审查 1.3 审查技巧 1.4 其他 引言: 编写完代码后就要上机测试代码,获得用户体验,筛选bug 笔者 ...
- 【Linux】CentOS8 初体验
一.部署CentOS8虚拟机 1.下载Centos8镜像 下载地址: https://www.centos.org/download/ 可以选择国内的下载源,比较快,这里推荐清华的和阿里的 2.下载完 ...
- ORA-00245 control file backup operation failed 分析和解决
一.问题说明 操作系统: RedHat 5.8 数据库: 11.2.0.3 2节点RAC. 使用RMAN 备份的时候,报如下错误: ORA-00245: control file backup fai ...
- Trollcave-suid提权
一 扫描端口 扫描开放端口:nmap -sV -sC -p- 192.168.0.149 -oA trollcave-allports 扫描敏感目录:gobuster dir -u http://19 ...
- 使用Adobe Arcobat Pro DC生成PDF提示“PDFMaker文件遗失”新解决思路
环境: 1.Window 7 2.Adobe Arcobat Pro DC 2020.009.20065 3.Microsoft Office 2007 4.WPS 2019 虽然可以使用插件实现文件 ...
- 面向对象的延伸与Java内部定义类的应用
识别类 传统的过程化程序设计,必须从顶部的main函数开始编写程序,在面向对象程序设计时没有所谓的"顶部".首先从设计类开始,然后再往每个类中添加方法. 识别类的规则是在分析问题的 ...
- vue3.0 composition API
一.Setup函数 1.创建时间:组件创建之前被调用,优先与created被调用,this指向的实例为window,created所指向的实例为proxy 2.this指向:不会指向组件实例 3.参数 ...
- windows ping bat脚本
参考百度链接:https://zhidao.baidu.com/question/577024998.html 要求:1.从同级目录下读取iplist.txt文件内的ip/域名列表(每行一个):2.对 ...
- https://www.cnblogs.com/wclwcw/p/7515515.html
https://www.cnblogs.com/wclwcw/p/7515515.html