1 #include<iostream> 2 #include <map> 3 #include <iomanip> 4 #include <string> 5 #include <cstring> 6 using namespace std; 7 map<string, bool>m[101];//如果第i个文件存在单词word,则m[i][word] = true; 8 int same[101][101] = { 0 }; 9 int num[101] = { 0 }; 10 int main() 11 { 12 int N; 13 cin >> N; 14 for (int i = 1; i <= N; i++) 15 { 16 char ch; 17 int cnt = 0; 18 char t_word[11]; 19 while ((ch = toupper(cin.get())) != '#')//统一转换为大写字母 20 { 21 if (ch >= 'A' && ch <= 'Z') 22 { 23 if (cnt < 10) t_word[cnt++] = ch;/*如果cnt>=10,则cnt不会增加,停留在第10个字母后边, 24 直至遇到第一个非字母时将t_word[cnt]置为'\0'*/ 25 } 26 else 27 { 28 t_word[cnt] = '\0'; 29 if (cnt >= 3) 30 { 31 m[i][t_word] = true; 32 } 33 cnt = 0; 34 } 35 } 36 map<string, bool>::iterator it; 37 for (it = m[i].begin(); it != m[i].end(); it++) 38 { 39 for (int j = 0; j < i; j++)//判断是否有相同的单词,每有一个sam[i][j]就加一 40 { 41 if (m[j][it->first] == true) 42 same[i][j] = same[j][i] += 1; 43 else 44 same[i][j] = same[j][i] += 0; 45 } 46 } 47 same[i][i] = num[i] = m[i].size(); 48 } 49 int M; 50 cin >> M; 51 for (int i = 0; i < M; i++) 52 { 53 int a, b; 54 cin >> a >> b; 55 cout << fixed << setprecision(1) << same[a][b] * 100.0 / (1.0 * (num[a] + num[b] - same[a][b])) << '%' << endl; 56 } 57 return 0; 58 }