#2
return_02020-01-28 12:03
|
#include <iostream>
#include <vector>
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<string> s;
string tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
s.push_back(tmp);
}
vector<vector<int>> num;
int temp;
int index = 0;
////////////////////输入num,num是二维数组,每一组数据有2个(空格分开);但是不知道一共有多数组数据从键盘输入////////////////////
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;
}
}