题解ios
一、先按大写字母进行字符串分割。spa
二、LIS 模板直接套用就行,这时就是单词而非数字,注意存储。code
想不到这一题居然是我惟一对的一题,我也是个小人才(/(ㄒoㄒ)/~~),我想哭呀,呜呜呜~~。blog
#include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <ctype.h> using namespace std; string str; vector <string> s; vector <vector <string> > ss; // 最长单调递增子序列 int main() { cin >> str; // 字符串分割操做 for (int i = 0; i < str.size(); ++i) { string t; t += str[i]; for (int j = i + 1; j < str.size(); ++j) { if (isupper(str[j])) { i = j - 1; break; } t += str[j]; if (j == str.size() - 1) i = j; } s.push_back(t); } // 最长上升子序列模板套用 vector <string> mmax; for (int i = 0; i < s.size(); ++i) { vector <string> tmp; // 计数最大值 int t = 1; for (int j = 0; j < i; ++j) { if (s[j] < s[i]) { if (t < ss[j].size() + 1) { t = ss[j].size() + 1; tmp = ss[j]; } } } tmp.push_back(s[i]); ss.push_back(tmp); if (mmax.size() < tmp.size()) { mmax = tmp; } } for (int i = 0; i < mmax.size(); ++i) { cout << mmax[i] << endl; } return 0; }