一、技术总结

  1. 学会使用substr(start, num);函数,同时注意题目中的要求,例如可能会出现按照格式输出0004,就不能够用%d格式输出,即使使用也需要注意。
  2. 同时stoi函数。

二、参考代码

#include<iostream>
#include<string>
using namespace std;
bool isPrime(int x){
	if(x == 0 || x == 1) return false;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) return false;
	}
	return true;
}
int main(){
	int L, K, cnt = 0;
	scanf("%d%d", &L, &K);
	string s;
	cin >> s;
	int num;
	for(int i = 0; i <= L - K; i++){
		string t = s.substr(i, K);
		num = stoi(t);
		if(isPrime(num)){
			cout << t;
			return 0;
		}
	}
	cout << "404";
	return 0;
}

相关文章:

  • 2021-08-31
  • 2021-12-27
  • 2022-12-23
  • 2022-02-22
  • 2022-12-23
  • 2021-06-13
  • 2022-01-06
  • 2021-12-04
猜你喜欢
  • 2021-12-12
  • 2022-01-03
  • 2021-10-21
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案