codeforces 174B File List 字符串 trick

代码敲的千疮百孔,其实题目不难

#include <iostream>
#include<deque>
#include<cstdio>
#define LMT 400005
using namespace std;
char str[LMT];
deque<int>po;
deque<int>ila;
//交这种题时,自己先早点测试数据
int main()
{
   int pre,now,next,i;
   bool yes=1;
    scanf("%s",str);
    po.push_back(-1);//字符串顶端
    for( i=0;str[i];i++)
      if(str[i]=='.')
      {
          po.push_back(i);
          if(po.size()==2&&(i<1||i>8))//看第一个文件名的长度,因为已经压入一个字符
          {
              yes=0;
              break;
          }
      }
      if(po.size()==1)//没有‘.的也是错的
      yes=0;
    po.push_back(i);
    pre=po.front();
    po.pop_front();
    while(!po.empty()&&yes)
    {
        now=po.front();
         po.pop_front();
        if(!str[now])break;
        if(!po.empty())next=po.front();
        else
        {
            yes=0;
            break;
        }
        for(i=1;i<=3&&now+i<next;i++)
            if((next-now-i-1<=8&&next-now-i-1>=1&&str[next])||(!str[next]&&!str[now+i+1]))//长判断先在纸上写一下吧
            {
               ila.push_back(i+now);
                break;
            }
         if(now+i==next||i>3)
         {
             yes=0;
             break;
         }
         pre=now;
    }
    if(yes)
    {
        printf("YES\n");
        i=0;
        while(!ila.empty())
        {
            now=ila.front();
            ila.pop_front();
            for(;i<=now;i++)
            printf("%c",str[i]);
            printf("\n");
        }
    }
    else printf("NO\n");
    return 0;
}


你可能感兴趣的:(codeforces 174B File List 字符串 trick)