zoukankan      html  css  js  c++  java
  • FZU 2183 字符串处理

    Problem Description

    现在有一些被简单压缩的字符串,例如:a[120]代表120个a。对于字符串acb[3]d[5]e相对于acbbbddddde

    现在给你两个字符串cString, nString.一个是被压缩过的字符串,另一个没有被压缩。

    求nString是否为cString的子串,如果是输出True,否则输出False.cString的长度clen的范围是0<clen<1000, nString的长度的nlen的范围是0<nlen<1000;cString只包含小写26个字母,[],数字(大于0小于10^9)。nString只包含小写26个字母。

     Sample Input

    acb[3]d[5]e bd

     Sample Output

    True

     Source

    FOJ有奖月赛-2015年03月

      1 #include <cstdio>
      2 #include <cmath>
      3 #include <cstring>
      4 #include <ctime>
      5 #include <iostream>
      6 #include <algorithm>
      7 #include <set>
      8 #include <vector>
      9 #include <queue>
     10 #include <typeinfo>
     11 #include <map>
     12 #include <stack>
     13 typedef long long ll;
     14 #define inf 0x7fffffff
     15 using namespace std;
     16 inline ll read()
     17 {
     18     ll x=0,f=1;
     19     char ch=getchar();
     20     while(ch<'0'||ch>'9')
     21     {
     22         if(ch=='-')f=-1;
     23         ch=getchar();
     24     }
     25     while(ch>='0'&&ch<='9')
     26     {
     27         x=x*10+ch-'0';
     28         ch=getchar();
     29     }
     30     return x*f;
     31 }
     32 
     33 //**************************************************************************************
     34 
     35 
     36 int main()
     37 {
     38     char a[1111];
     39     char b[1111];
     40     char aa[1111];
     41     char bb[1111];
     42     int bna[1111];
     43     int ana[1111];
     44     while(scanf("%s%s",a,b)!=EOF)
     45     {
     46         int l=strlen(b);
     47         int k=0;
     48         int now=0;
     49         bb[++k]=b[0];
     50         bna[k]=1;
     51         for(int i=1; i<l; i++)
     52         {
     53             if(b[i]!=b[i-1])
     54             {
     55                 now=1;
     56                 bb[++k]=b[i];
     57                 bna[k]=1;
     58             }
     59             else
     60             {
     61                 now++;
     62                 bna[k]=now;
     63             }
     64         }
     65         int bk=k;
     66         k=0;
     67         aa[k]='0';
     68         int la=strlen(a);
     69         for(int i=0; i<la; i++)
     70         {
     71             if(a[i]>='a'&&a[i]<='z')
     72             {
     73                 aa[++k]=a[i];
     74                 ana[k]=1;
     75             }
     76             else if(a[i]=='[')
     77             {
     78                 int sum=0;
     79                 i++;
     80                 while(a[i]!=']')
     81                 {
     82                     sum*=10;
     83                     sum+=a[i]-'0';
     84                     i++;
     85                 }
     86                 ana[k]=sum;
     87                 if(aa[k]==aa[k-1])
     88                 {
     89                     //  if(k==5)printf("%c %d
    ",aa[k],ana[k]);
     90                     ana[k-1]+=ana[k];
     91                     k--;
     92                 }
     93             }
     94 
     95         }
     96         int ak=k;
     97 
     98 
     99         if(bk>ak)
    100         {
    101             printf("False
    ");
    102             continue;
    103         }
    104         int das=0;
    105         for(int i=1; i<=ak-bk+1; i++)
    106         {
    107             bool flag=true;
    108             for(int j=i; j<i+bk; j++)
    109             {
    110                 if(j==i||j==i+bk-1)
    111                 {
    112                     if(aa[j]!=bb[j-i+1])
    113                     {
    114 
    115                         flag=false;
    116                         break;
    117                     }
    118 
    119                 }
    120                 else
    121                 {
    122                     if(aa[j]!=bb[j-i+1]||ana[j]!=bna[j-i+1])
    123                     {
    124                         flag=false;
    125                         break;
    126                     }
    127                 }
    128             }
    129 
    130             if(flag)
    131             {
    132                 printf("True
    ");
    133                 das=1;
    134                 break;
    135             }
    136         }
    137         if(!das)
    138         printf("False
    ");
    139     }
    140 
    141     return 0;
    142 }
  • 相关阅读:
    table首行固定
    JavaScript获取当前日期,昨天,今天日期以及任意天数间隔日期
    Struts2二级菜单联动
    Servlet和Struts2同时使用
    最近的感想
    java.lang.NoClassDefFoundError: javax/el/ELResolver 问题解决
    Event Loop、函数式编程、IO多路复用、事件驱动、响应式、
    Git 的使用(一)
    Linux 硬链接与软链接 目录结构
    并发、并行、同步、异步相关感念
  • 原文地址:https://www.cnblogs.com/zxhl/p/4696668.html
Copyright © 2011-2022 走看看