题目:1114 全素日 - PAT (Basic Level) Practice (中文) (pintia.cn)
对不是素数的做个标记,只要有一个不是素数就不能输出"ALL prime!"
#include<bits/stdc++.h>
using namespace std;
int flag;
bool isprime(string s)
{
int x=stoi(s);
if(x<2)return 0;
for(int i=2;i*i<=x;i++)
{
if(x%i==0)return false;
}
return true;
}
int main()
{
string s;cin>>s;
for(int i=0;i<s.size();i++)
{
string temp=s.substr(i);
if(isprime(temp))
{
cout<<temp<<" "<<"Yes"<<endl;
}
else
{
flag=1;
cout<<temp<<" "<<"No"<<endl;
}
}
if(flag)cout<<"All Prime!"<<endl;
return 0;
}