File tree Expand file tree Collapse file tree
leetcode/Study Plan/28. 找出字符串中第一个匹配项的下标 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ * @Author: tkzzzzzz6
3+ * @Date: 2026-04-13 11:23:16
4+ * @LastEditors: tkzzzzzz6
5+ * @LastEditTime: 2026-04-14 01:42:29
6+ */
7+ /*
8+ * @acwing app=acwing.cn id=3529 lang=C++
9+ *
10+ * 3526. 素数
11+ */
12+
13+ // @acwing code start
14+ #include < iostream>
15+
16+ using namespace std ;
17+
18+ bool is_prime (int x){
19+ if (x < 2 || x % 2 == 0 )return false ;
20+ for (int i = 2 ;i<=x/i;++i){
21+ if (x % i == 0 )return false ;
22+ }
23+ return true ;
24+ }
25+
26+ int main (){
27+ int n;
28+ while (cin >> n){
29+ int cnt = 0 ;
30+ for (int i = 2 ;i<n;i = (i / 10 + 1 )*10 + 1 ){
31+ if (is_prime (i)){
32+ ++cnt;
33+ cout << i << ' ' ;
34+ }
35+ }
36+ if (!cnt) cout << -1 ;
37+ cout << endl;
38+ }
39+ return 0 ;
40+ }
41+
42+ // @acwing code end
Original file line number Diff line number Diff line change 11/*
22 * @Author: tkzzzzzz6
3- * @Date: 2026-04-14 01:07:56
3+ * @Date: 2026-04-14 01:08:25
44 * @LastEditors: tkzzzzzz6
5- * @LastEditTime: 2026-04-14 01:08:01
5+ * @LastEditTime: 2026-04-14 01:21:50
66 */
7+ /*
8+ * @lc app=leetcode.cn id=28 lang=cpp
9+ * @lcpr version=30204
10+ *
11+ * [28] 找出字符串中第一个匹配项的下标
12+ */
13+
14+
15+ // @lcpr-template-start
16+ using namespace std ;
17+ #include < algorithm>
18+ #include < array>
19+ #include < bitset>
20+ #include < climits>
21+ #include < deque>
22+ #include < functional>
23+ #include < iostream>
24+ #include < list>
25+ #include < queue>
26+ #include < stack>
27+ #include < tuple>
28+ #include < unordered_map>
29+ #include < unordered_set>
30+ #include < utility>
31+ #include < vector>
32+ // @lcpr-template-end
33+ // @lc code=start
734class Solution {
835public:
936 int strStr (string haystack, string needle) {
10- int n = haystack.size (),m = needle
37+ int m = haystack.size (),n = needle.size ();
38+ if (n == 0 )return -1 ;
39+ string s = needle + ' #' + haystack;
40+ vector<int > pi (s.size ());
41+ for (int i = 1 ;i<s.size ();++i){
42+ int len = pi[i - 1 ];
43+ while (len && s[i] != s[len]){
44+ len = pi[len-1 ];
45+ }
46+ if (s[i] == s[len]){
47+ pi[i] = len + 1 ;
48+ if (pi[i] == n)return i-2 *n;
49+ }
50+ }
51+ return -1 ;
1152 }
1253};
54+ // @lc code=end
55+
56+
57+
58+ /*
59+ // @lcpr case=start
60+ // "sadbutsad"\n"sad"\n
61+ // @lcpr case=end
62+
63+ // @lcpr case=start
64+ // "leetcode"\n"leeto"\n
65+ // @lcpr case=end
66+
67+ */
You can’t perform that action at this time.
0 commit comments