目录
- 👉🏻字符串反转
- 👉🏻公共子串计算
👉🏻字符串反转
mycode:100%
#include <iostream>
#include<algorithm>
using namespace std;int main() {string s;cin>>s;reverse(s.begin(),s.end());cout<<s<<endl;
}
👉🏻公共子串计算
mycode:100%
#include <iostream>
using namespace std;int main() {string s1, s2;cin >> s1 >> s2;//s1所有字串组合在s2中遍历寻找int size = s1.size();int maxlen = 0;for (int i = 0; i < s1.size(); i++){for (int j = i+1; j <= size; j++){string tmp(s1.begin() + i, s1.begin() + j);if (s2.find(tmp) != string::npos){if (tmp.size() > maxlen)maxlen = tmp.size();}}}cout << maxlen << endl;
}
string迭代器左闭右开!