Advertisement
Debashish_Saha

uva 10141

May 12th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     //freopen("1.txt","r",stdin);
  6.     //freopen("2.txt","w",stdout);
  7.  
  8.     int n,p,r[10001];
  9.  
  10.     double d[10001];
  11.     int ct[10001];
  12.     string s1[10001],s2[10001];
  13.     string x[10001];
  14.     int t=0;
  15.     while( cin>>n>>p && (n || p) ) {
  16.         cin.ignore();
  17.         t++;
  18.         for(int i=0; i<n; i++) {
  19.             getline(cin,s1[i]);
  20.         }
  21.  
  22.         for(int i=0; i<p; i++) {
  23.             getline(cin, x[i]);
  24.             cin>>d[i]>>r[i];
  25.             cin.ignore();
  26.             for(int j=0; j<r[i]; j++) {
  27.                 getline(cin,s2[j]);
  28.             }
  29.             ct[i]=0;
  30.             for(int j=0; j<r[i]; j++) {
  31.                 for(int k=0; k<n; k++) {
  32.                     if(s2[j]==s1[k]) {ct[i]++; break;}
  33.                 }
  34.             }
  35.         }
  36.  
  37.         int mx=0;
  38.         int pos=0;
  39.  
  40.         for(int i=0; i<p; i++) {
  41.             if(ct[i]>mx) {
  42.                 mx=ct[i];
  43.                 pos=i;
  44.             }
  45.             else if(ct[i]==mx) {
  46.                 if(d[i]<d[pos]) pos = i;
  47.             }
  48.  
  49.         }
  50.  
  51.  
  52.         if(t>1) printf("\n");
  53.         printf("RFP #%d\n",t);
  54.         cout<<x[pos]<<endl;
  55.         //memset(ct,0,sizeof(ct));
  56.         //memset(d,0,sizeof(d));
  57.         //memset(r,0,sizeof(r));
  58.  
  59.     }
  60.  
  61.  
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement