題解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; }