C++不定数据长度输入
#include
#include
using std::vector;
using std::string;
using std::cin;
using std::cout;
int LCS(string s1, string s2) {
int res = 0;
int a = 0;
int b = 0;
for (int i = 0, j = 0; i < s1.size() && j < s2.size(); i++, j++) {
if (s1[i] == s2[j])
res++;
else
break;
}
return res;
}
int main() {
int n;
cin >> n;
vector s;
string tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
s.push_back(tmp);
}
vector> num;
int temp;
int index = 0;
while (cin.get()){
cin >> temp;
num[index][0] = int(temp);
cin >> temp;
num[index][1] = int(temp);
//num[index][1].push_back(temp);
}
for (int i = 0; i < num.size(); i++) {
int a = num[i][0];
int b = num[i][1];
int res = LCS(s[a], s[b]);
cout << res;
}
}
阅读(876) | 评论(0) | 转发(0) |