HUN 11006 居然re了这么多次还没过,,,郁闷,,,,明天继续

#include <iostream>
using namespace std;

struct par
{
       string ma;
       string fa;
}pp[100][1000];

 

string checkss(string a,string b,string c)
{
       string re="";
       int len=c.length();
       for(int i=0;i<len;i++)
         { if(c[i]=='R')
            {
            if(a[i]=='1'&&b[i]=='1')
               re+='1';
            else
               re+='0';
            }
          else if(c[i]=='D')
          {
              if(a[i]=='0'&&b[i]=='0')
               re+='0';
              else
               re+='1';
          }
       }
       return re;
}

int cd(string a,string b)
{
    int len,w;
    len=a.length()>b.length()?b.length():a.length();
    for(w=0;w<len;w++)
      {
            if(a[w]<b[w]) return -1;
            else if(a[w]>b[w]) return 1;
      }
      if(w==len)  return 0;
}

int cmp( const void *a , const void *b )
{
struct par *c = (par *)a;
struct par *d = (par *)b;
if(cd(c->ma,d->ma)==0)
return cd(c->fa,d->fa);
else
return cd(c->ma,d->ma);
}

string ffff[1000];
string mmmm[1000];

string fm[1000];
string fn[1000];

string te1[1000],te2[1000];
string cte[1000];
string cs[1000];
string t;
string kk[1000];


int main()
{int mi,fi,cc;
int flag;
int sstt[1000];
string s,q;
char p;
   while(cin>>t)
    {
                 mi=0;flag=0;fi=0;cc=0;
                 for(int rr=0;rr<1000;rr++)
                    sstt[rr]=0;
       while (cin>>s)
        {
             if(s=="***"&&flag==0)
               {   flag=1;
               }
             else if(s=="***"&&flag==1)
             {
                 flag=0;break;
             }
             else if(s!="***"&&flag==0)
              {
                cin>>p>>q;
                if(p=='M')
                   {
                       ffff[fi]=s;
                       fm[fi]=p;
                       te1[fi]=q;
                       fi++;
                   }
                if(p=='F')
                   {
                       mmmm[mi]=s;
                       fn[mi]=p;
                       te2[mi]=q;
                       mi++;
                   }
                }
              else if(s!="***"&&flag==1)
              {
                cs[cc]=s;
                cin>>cte[cc];
                cc++;              
              }
             
        } 
                       
        int pk=0;
        for(int i=0;i<fi;i++)
           for(int j=0;j<mi;j++)
               {
                   kk[pk]=checkss(te1[i],te2[j],t);
                   for(int rr=0;rr<cc;rr++)
                     if(cte[rr]==kk[pk])
                       {
                          pp[rr][sstt[rr]].fa=ffff[i];
                          pp[rr][sstt[rr]].ma=mmmm[j];
                          sstt[rr]++;
                       }
                   pk++;   
               }
                             
               for(int l=0;l<cc;l++)
              qsort(pp[l],sstt[l],sizeof(pp[l][0]),cmp);
              
               for(int oo=0;oo<cc;oo++)
               {            
                    cout<<cs[oo]<<" by ";
                    if(sstt[oo]<1) cout<<endl;
                    else
                    {
                        cout<<pp[oo][0].ma<<"-"<<pp[oo][0].fa;
                        for(int pq=1;pq<sstt[oo];pq++)
                          cout<<" or "<<pp[oo][pq].ma<<"-"<<pp[oo][pq].fa;             
                          cout<<endl;
                    }
               }
    }
 return 0;
   
}

 

posted on 2007-09-15 00:25  xmx  阅读(238)  评论(0)    收藏  举报

导航