當(dāng)前位置:
首頁 >
9.10 中国电信it研发中心 笔试编程题
發(fā)布時(shí)間:2024/3/26
51
豆豆
生活随笔
收集整理的這篇文章主要介紹了
9.10 中国电信it研发中心 笔试编程题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
A
題意: 假設(shè)字符串中出現(xiàn)次數(shù)最少的字母是x, 出現(xiàn)次數(shù)為y, 刪除所有出現(xiàn)次數(shù)為y的字符
思路: 統(tǒng)計(jì)一下字符的出現(xiàn)次數(shù), 然后照著做就行
B
題意: 求第n個(gè)丑數(shù)
思路: leetcode原題, 可以去leetcode找一找
C
題意: 求兩個(gè)串前后重疊部分的最大長度
思路: 最初我是采用這種暴力計(jì)算的方法, 可以ac
之后想了想發(fā)現(xiàn)其實(shí)就是個(gè)kmp問題, 跑兩次kmp即可 時(shí)間復(fù)雜度O(n)
#include <iostream> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <stack> #include <queue> #include <utility> #include <map> #include <set> #include <cstdio> #include <sstream> #include <cctype>#define LL long long #define mst(a, b) memset(a, b, sizeof(a)) #define pill pait<int, int> #define ft first #define sd secondusing namespace std;const int qq = 3e5 + 10; const int MOD = 1e9 + 7; const int INF = 1e9 + 10; string x, y; int nt[qq]; void getNext(string f) {int i = 0, j = -1;nt[0] = -1;int len = f.size();while (i < len) {if (j == -1 || f[i] == f[j]) {nt[++i] = ++j;} else {j = nt[j];}} } int getMaxn(string x, string y) {int i = 0, j = 0;int len = x.size();while (i < len) {if (j == -1 || x[i] == y[j]) {i++, j++;} else {j = nt[j];}}return j; }int main() {std::ios::sync_with_stdio(false);cin >> x >> y;getNext(x);int maxn = getMaxn(y, x);getNext(y);maxn = max(maxn, getMaxn(x, y));cout << maxn << endl;return 0; }總結(jié)
以上是生活随笔為你收集整理的9.10 中国电信it研发中心 笔试编程题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 每日新闻丨马电信运营商与华为签署5G商
- 下一篇: 单片机——蝙蝠超声思想避物小车