The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool "Prime Day". That is, not only that the corresponding number of the date 20190523 is a prime, but all its sub-strings ended at the last digit 3 are prime numbers.

Now your job is to tell if a given date is a Prime Day.

Input Specification:

Each input file contains one test case. For each case, a date between January 1st, 0001 and December 31st, 9999 is given, in the format yyyymmdd.

Output Specification:

For each given date, output in the decreasing order of the length of the substrings, each occupies a line. In each line, print the string first, followed by a space, then Yes if it is a prime number, or No if not. If this date is a Prime Day, print in the last line All Prime!.

Sample Input 1:

20190523
 

Sample Output 1:

20190523 Yes
0190523 Yes
190523 Yes
90523 Yes
0523 Yes
523 Yes
23 Yes
3 Yes
All Prime!
 

Sample Input 2:

20191231

Sample Output 2:

20191231 Yes
0191231 Yes
191231 Yes
91231 No
1231 Yes
231 No
31 Yes
1 No

复习一下string的截取操作str.substr(begin_index,end_index);

以及string to int 操作stoi(str);

 1 #include<bits/stdc++.h>
2 using namespace std;
3 bool isPrime(int num){
4 if (num==1)
5 return false;
6 if (num==2)
7 return true;
8 for(int i=2;i<=num/2;++i){
9 if (num%i==0)
10 return false;
11 }
12 return true;
13 }
14 int main(){
15 string input;
16 cin>>input;
17 int count=0;
18 for (int i=0;i<input.size();++i){
19 string str_temp=input.substr(i,input.size()); //常用string截取函数
20 int int_temp=stoi(str_temp); //常用string转数字函数
21 cout<<str_temp<<" ";
22 if (isPrime(int_temp)){
23 cout<<"Yes"<<endl;
24 }
25 else{
26 cout<<"No"<<endl;
27 count++;
28 }
29 }
30 if (count==0){
31 cout<<"All Prime!"<<endl;
32 }
33 }


1168 Prime Day(20)的更多相关文章

  1. PAT-乙级-1039. 到底买不买(20)

    1039. 到底买不买(20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 小红想买些珠子做一串自己喜欢的珠串 ...

  2. PAT-乙级-1037. 在霍格沃茨找零钱(20)

    1037. 在霍格沃茨找零钱(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 如果你是哈利·波特迷,你会知 ...

  3. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(20)-权限管理系统-根据权限获取菜单

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(20)-权限管理系统-根据权限获取菜单 不知不觉到20讲,真是漫长的日子,可惜最近工作挺忙,要不可以有更多 ...

  4. Windows Phone开发(20):当MediaElement和VideoBrush合作的时候

    原文:Windows Phone开发(20):当MediaElement和VideoBrush合作的时候 前面说的那么多控件都是"静态"的,都是"哑吧"的,今天 ...

  5. PAT 1037 在霍格沃茨找零钱(20)(代码+思路)

    1037 在霍格沃茨找零钱(20)(20 分) 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon) ...

  6. PAT 1039 到底买不买(20)(20 分)

    1039 到底买不买(20)(20 分) 小红想买些珠子做一串自己喜欢的珠串.卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖.于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要 ...

  7. Java设计模式(20)观察者模式(Observer模式)

    Java深入到一定程度,就不可避免的碰到设计模式(design pattern)这一概念,了解设计模式,将使自己对java中的接口或抽象类应用有更深的理解.设计模式在java的中型系统中应用广泛,遵循 ...

  8. PAT 乙级 1037 在霍格沃茨找零钱(20)C++版

    1037. 在霍格沃茨找零钱(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 如果你是哈利·波特迷,你会知 ...

  9. leecode刷题(20)-- 删除链表中的节点

    leecode刷题(20)-- 删除链表中的节点 删除链表中的节点 描述: 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 -- head = ...

  10. Qt 学习之路 2(20):event()

    Qt 学习之路 2(20):event() 豆子 2012年10月10日 Qt 学习之路 2 43条评论 前面的章节中我们曾经提到event()函数.事件对象创建完毕后,Qt 将这个事件对象传递给QO ...

随机推荐

  1. JZOJ 3479. 工作安排

    \(\text{solution}\) 比较显然的 \(dp\) 顺序既然无所谓,那为了方便处理贡献,就先排个序 然后设 \(f_i\) 表示分到前 \(i\) 个的最小工资 则 \(f_i=C+f_ ...

  2. 两个集合之间数据过滤linq

    //以下为前台多字段循环匹配if (!input.Filter.IsNullOrEmpty()) { var keysList = input.Filter.Split(" ".T ...

  3. Jmix- 业务系统高效开发的少代码平台

    企业在数字化转型的过程中,都面临将现有的业务流程进行"软件化"的过程.然而,在我们的印象中,通常会觉得针对业务系统的软件开发不是特别高效.这背后有很多原因,从开发角度看,有一个主要 ...

  4. c# 游戏设计:地图移动

    想实现一个小游戏,先做地图移动.步骤记录如下: 1.百度到一张大的迷宫地图,放在项目的debug目录下,备用. 2.创建一个winform项目,不添加任何界面元素. 3.添加数据成员如下: Pictu ...

  5. Educational Codeforces Round 137 (Rated for Div. 2) - D. Problem with Random Tests

    期望 + 暴力 [Problem - D - Codeforces](https://codeforces.com/contest/1743/problem/E) 题意 给出一个长度为 \(n\;(1 ...

  6. 2023 年 CCF 春季测试赛模拟赛 - 1

    T1 个人思路: 询问:求 \(1\) 到 \(t_i\) 路径上离 \(1\) 最远的 \(p\),使得 \(dis_{1,p} \times 2 \le d_i\).即 \(dis_{1,t} \ ...

  7. 【python操作Excel的常见方法汇总】 xlrd pandas xlwings

    用python处理Excel数据,实现Excel的功能:分列.透视等功能 1. Excel 解压文件 #解压tar_path中的压缩文件到uzipPath def unzip_archive(tar_ ...

  8. vue部署样式错乱

    1 <style scoped> 2 .el-menu-vertical-demo:not(.el-menu--collapse) { 3 border: none; 4 } 5 .sub ...

  9. 对NAN的认识

    NaN是个特殊的数值,它与任何值都不相等,包括它自己,NaN==NaN和NaN===NaN都是false,如果想测试某个数字是否为NaN,可以使用内置的函数isNaN(),如果是NaN则返回true, ...

  10. ElasticSearch、ElasticSearch-head的安装和问题解决

    前言:elasticsearch作为一个基于Lucene的分布式搜索引擎,其搜索功能的强大之处不用多说,而elasticsearch-head作为一个node项目,能够轻松管理elasticsearc ...