4879 - Old Fafhioned Typefetting 最蛋疼的一道题 题意实在是理解不了15次WA

#include <iostream>//http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2880
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#define MAX 10000

using namespace std;

char str[MAX];


void typesetting()
{
    int len = strlen(str);

    for(int i = 0;i < len;i++)
    {
        if(!isalpha(str[i])){
            cout<<str[i];
            continue;
        }

        if(str[i] != 'A' && str[i]!= 'a'
           && str[i]!= 'c' && str[i]!= 'f'
           && str[i]!= 's'&& str[i]!= 'O'
           && str[i]!= 'o')
        {
            cout<<str[i];
            continue;
        }

        switch(str[i])
        {
            case 'A':
              if(i < len-1 && (str[i+1] == 'E' || str[i+1] == 'e'))
              {
                  cout<<"[AE]";i++;
              }
              else cout<<str[i];
              break;

            case 'a':
              if(i < len-1 && (str[i+1] == 'e'|| str[i] == 'E' ))
              {
                  //if(str[i] == 'e')
                  cout<<"[ae]";
                 // else cout<<"[AE]";
                  i++;
              }
              else cout<<str[i];
              break;

            case 'O':
              if(i < len-1 && (str[i+1] == 'E' || str[i+1] == 'e'))
              {
                  cout<<"[OE]";
                  i++;
              }
              else cout<<str[i];
              break;

            case 'o':
              if(i < len-1 && (str[i+1] == 'e' || str[i+1] == 'E' ))
              {
                  //if(str[i] == 'e')
                    cout<<"[oe]";
                 // else cout<<"[OE]";
                  i++;
              }
              else cout<<str[i];
              break;


            case 'c':
              if(i < len-1 && str[i+1] == 't')
              {
                  cout<<"[ct]";i++;
              }
              else cout<<str[i];
              break;

           case 'f':
           {
               if(i < len-1)
               {
                   char c = str[i+1];

                   if(c == 'i' || c == 'l')
                   {
                       cout<<"[f"<<c<<']';
                       i++;
                   }
                   else if(c != 'f')
                    cout<<str[i];
                   else{
                       int flage = 1;
                       if(i < len - 2)
                       {
                           char cc = str[i+2];
                           if(cc == 'i' || cc == 'l' )
                           {
                               flage = 0;
                               cout<<"[ff"<<cc<<']';
                               i += 2;
                           }
                       }

                       if(flage)
                       {
                           i++;
                           cout<<"[ff]";
                       }

                   }
               }
               else cout<<str[i];

               break;
           }

           case 's':
           {
               if(i == len -1
                  || !isalpha(str[i+1])
                  || str[i+1] == 'f' || str[i+1] == 'b'
                  || str[i+1] == 'k')
              {
                  cout<<str[i];
              }
              else{
                  char c = str[i+1];
                  if(c == 'i' || c == 'h' || c== 'l' || c == 't')
                  {
                       cout<<"[longs"<<c<<']';
                       i++;
                       continue;
                  }
                  else if(c != 's')
                  {
                      cout<<"[longs]";
                      continue;
                  }
                  else
                  {
                      if(str[i-1] == 's')
                      {
                         cout<<str[i];
                         continue;
                      }

                      int flage = 1;
                       if(i < len - 2)
                       {
                           char cc = str[i+2];
                           if(cc == 'i' )
                           {
                               flage = 0;
                               cout<<"[longss"<<cc<<']';
                               i += 2;
                           }

                           if(cc == 's')
                           {
                               cout<<"[longs]";
                               flage = 0;
                           }

                       }

                       if(flage)
                       {
                           if(i < len - 2 && isalpha(str[i+2]) && str[i+2] != 'f' && str[i+2] != 'b'
                            && str[i+2] != 'k')
                           {
                               i++;
                               cout<<"[longss]";
                           }
                           else{
                               cout<<"[longs]";
                           }
                       }

                  }

              }

              break;
           }

        }
    }
}

int main()
{
    //freopen("in.in","r",stdin);

    int test_case;
    cin>>test_case;
    while(test_case--)
    {
        int cas; cin>>cas; cout<<cas;
        memset(str,0,sizeof(str));

        /*int cu = 0;
        while(1)
        {
            while((str[cu++] = getchar()) == EOF) break;
            if(str[cu-1] == '\n'){str[cu-1] = 0; break;}
        }
        */
        gets(str);
        int len = strlen(str);


        typesetting();
        cout<<endl;
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值