BNU 51002 BQG's Complexity Analysis

模拟

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

const int maxn=100+10;
char t1[maxn],t2[maxn];
int g1,g2,h1,h2;



int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        g1=g2=h1=h2=0;
        scanf("%s%s",t1,t2);

        if(t1[2]=='n') g1=1;
        if(t1[3]=='^')
        {
            g1=0;
            for(int i=4;;i++)
            {
                if(t1[i]>='0'&&t1[i]<='9') g1=g1*10+t1[i]-'0';
                else break;
            }
        }

        int pos=-1;
        int len=strlen(t1);
        for(int i=0;t1[i];i++)
        {
            if(i+3<len&&t1[i]=='l'&&t1[i+1]=='o'&&t1[i+2]=='g'&&t1[i+3]=='n')
            {
                h1=1;
                pos=i+6;
                break;
            }
        }
        if(pos!=-1)
        {
            int sum=0;
            for(int i=pos;i<len;i++)
            {
                if(t1[i]>='0'&&t1[i]<='9') sum=sum*10+t1[i]-'0';
                else break;
            }
            h1=max(h1,sum);
        }


        if(t2[2]=='n') g2=1;
        if(t2[3]=='^')
        {
            g2=0;
            for(int i=4;;i++)
            {
                if(t2[i]>='0'&&t2[i]<='9') g2=g2*10+t2[i]-'0';
                else break;
            }
        }

         pos=-1;
         len=strlen(t2);
        for(int i=0;t2[i];i++)
        {
            if(i+3<len&&t2[i]=='l'&&t2[i+1]=='o'&&t2[i+2]=='g'&&t2[i+3]=='n')
            {
                h2=1;
                pos=i+6;
                break;
            }
        }
        if(pos!=-1)
        {
            int sum=0;
            for(int i=pos;i<len;i++)
            {
                if(t2[i]>='0'&&t2[i]<='9') sum=sum*10+t2[i]-'0';
                else break;
            }
            h2=max(h2,sum);
        }

      //  printf("%d %d\n",g1,h1);
      //  printf("%d %d\n",g2,h2);

      if(g1<g2) printf("First\n");
      else if(g1>g2) printf("Second\n");
      else
      {
          if(h1<h2) printf("First\n");
          else if(h1>h2) printf("Second\n");
          else printf("Both\n");
      }

    }
    return 0;
}

 

posted @ 2015-12-26 11:31  Fighting_Heart  阅读(176)  评论(0编辑  收藏  举报