PAT甲级1152 Google Recruitment :[C++题解]判质数
生活随笔
收集整理的這篇文章主要介紹了
PAT甲级1152 Google Recruitment :[C++题解]判质数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 題目分析
- 題目來源
題目分析
來源:acwing
分析:判質數,10位以內。
ac代碼
#include<bits/stdc++.h> using namespace std;int n , k; bool is_prime(int n){if(n <= 1) return false;for(int i = 2; i<= n/i; i++)if(n %i ==0) return false;return true; }int main(){cin >> n >> k;string s;cin >> s;bool find = false;string t;for(int i = 0; i<n;i ++){if(i+k<=n){t = s.substr(i,k);if(is_prime(stoi(t))){find = true;break;}} }if(find) cout<<t<<endl;else cout<<"404"<<endl;}如果出現運行時錯誤,大多數是數組越界。
題目來源
PAT甲級1152 Google Recruitment
https://www.acwing.com/problem/content/1648/
總結
以上是生活随笔為你收集整理的PAT甲级1152 Google Recruitment :[C++题解]判质数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PAT甲级1116 Come on! L
- 下一篇: PAT甲级1008 Elevator:[