谷歌的招聘

题目就自己上链接看吧
刚开始因为没有注意保持要求的输出位数,第三个测试点通不过。
比如输入为:

6 4
200236 

虽然答案应该是23,但是你得输出0023,就是这么个原因。
加了两句就OK了

cout.width(K);
cout.fill('0');

以下是AC的代码

#include <iostream>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
bool IsPrime(long long num){
   
    if (num <= 1)return false;
    for (unsigned int i = 2; i <= sqrt(num); i++)
        if (!(num % i))    return false;    
    return true;
}
int main(){
   
    string str;
    unsigned int L, K;
    cin >> L >> K >> str;
    for (int i = 0; i < L - K + 1; i++){
   
        string tt = str.substr(i, K);
        auto tmp = atoi(tt.c_str());
        if (IsPrime(tmp){
   
            cout.width(K);
            cout.fill('0');
            cout << tmp << endl;
            return 0;
        }
    }
    cout << "404" << endl;
    return 0;
}