FZU 2183 简单题(字符串匹配|字符串压缩)(简单)
来源:互联网 发布:淘宝人脸认证为何失败 编辑:程序博客网 时间:2024/06/06 15:44
Problem 2183 简单题
Accept: 138 Submit: 641
Time Limit: 1000 mSec Memory Limit : 32768 KB
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]ebd
Sample Output
True
思路:
直接暴力就可以,但是要注意的是每个位置记录字母的类型和数量然后直接暴力就可以了。但是要注意c[3]c[5]这种数据。
代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include<iostream>using namespace std;#define N 1005typedef long long ll;struct C{ int cnt; char ch;};C A[N], B[N];int main(){ while (1) { for (int i = 0; i < N; i++) { A[i].cnt = 1; } char temp, t = ' '; int cnt1 = -1, cnt2 = -1; while (scanf("%c", &temp), temp != '\n') { if (t == temp) A[cnt1].cnt++; else if (temp != '[' && t != temp) { cnt1++; } if (temp >= 'a' && temp <= 'z') { A[cnt1].ch = temp; t = temp; } if (temp == '[') { int num; scanf("%d%*c", &num); A[cnt1].cnt = num; } } t = ' '; while (scanf("%c", &temp), temp != '\n') { if (temp >= 'a' && temp <= 'z' && temp != t) { B[++cnt2].ch = temp; B[cnt2].cnt = 1; t = temp; } else if (temp == t) { B[cnt2].cnt++; } } /* for(int i=0;i<=cnt1;i++) cout<<A[i].ch<<" "; cout<<endl; for(int i=0;i<=cnt1;i++) cout<<A[i].cnt<<" "; cout<<endl; for(int i=0;i<=cnt2;i++) cout<<B[i].ch<<" "; cout<<endl; for(int i=0;i<=cnt2;i++) cout<<B[i].cnt<<" "; cout<<endl; */ int flag = 0; for (int i = 0; i <= cnt1; i++) { if (A[i].ch == B[0].ch && A[i].cnt >= B[0].cnt) { int flag2 = 1; for (int j = 1; j < cnt2; j++) { if (A[i + j].ch != B[j].ch || A[i + j].cnt != B[j].cnt) { flag2 = 0; break; } } if (flag2) { if (A[i + cnt2].ch == B[cnt2].ch && A[i + cnt2].cnt >= B[cnt2].cnt) { flag = 1; break; } } } } if (cnt1 == -1 && cnt2 == -1) break; if (flag) printf("True\n"); else printf("False\n"); } return 0;}
0 0
- FZU 2183 简单题(字符串匹配|字符串压缩)(简单)
- FZU Problem 2183 简单题(字符串处理)
- 简单字符串的压缩
- 简单的压缩字符串
- poj1035 简单字符串匹配
- 字符串简单匹配算法
- 简单字符串匹配方法
- 简单字符串 * 匹配
- 简单字符串匹配
- 简单字符串循环压缩算法
- 1361 字符串匹配简单版
- 简单的字符串匹配 poj1936
- 简单的字符串近似匹配
- 简单正则表达式匹配字符串
- 字符串的简单模式匹配
- 简单的字符串模式匹配
- 简单的字符串匹配算法
- 简单的字符串匹配算法
- hdu 1690 floyd
- (1)把一个存在工程加入git管理
- hdu5344MZL's xor
- Android之——杀死用户选中的进程优化
- 深入剖析Android四大组件(七)——Activity启动的4个阶段
- FZU 2183 简单题(字符串匹配|字符串压缩)(简单)
- JAVA基础一大堆0804反射+注解
- Java学习笔记 线程,注解(注释)...
- 乘法逆元 & hdu 1576 A/B
- shape(二)
- ocp知识点:控制事务
- 1026. Table Tennis (30)
- 利用MyBatis生成器自动生成实体类、DAO接口和Mapping映射文件
- Java方法中的参数传递方式