1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include <bits/stdc++.h> #define ll long long #define int long long #define double long double #define N 105 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define rrep(i,l,r) for(int i=l;i<r;i++) #define pii pair<int,int> #define pif pair<int,float> #define x first #define y second using namespace std; int n,num_key = 0; string key[N]; vector<pif> ans;
int com_string(string s1, string s2){ s1 = "0"+s1;s2 = "0"+s2; int ans = 0,com[N][N];memset(com,0,sizeof(com)); int len1 = s1.size(),len2 = s2.size(); for(int i=1;i<len1;i++){ for(int j=1;j<len2;j++){ if(s1[i] == s2[j]){ com[i][j] = com[i-1][j-1]+1; ans = max(ans,com[i][j]); } } } return ans; }
bool cmp(pif a,pif b){ if(a.y == b.y)return a.x < b.x; return a.y > b.y; }
float max_num(string s){ float ans = 0.0; for(int i=0;i<num_key;i++){ ans = max(ans,(float)com_string(s,key[i])/key[i].size()); } return ans; }
signed main(){ string s;getline(cin,s); stringstream ss(s); while(ss>>key[num_key++]); cin>>n;cin.ignore(); while(n--){ int doc_num; getline(cin,s); stringstream ss2(s); ss2>>doc_num; float score = 0.0; while(ss2 >> s)score += max_num(s); score = round(score*100)/100; ans.push_back({doc_num,score}); } sort(ans.begin(),ans.end(),cmp); if(ans[0].y <= 0)cout<<"FALSE"<<endl; else for(auto i: ans)cout<<i.x<<" "; }
|