Codeforces_358B_Dima and Text Messages(字符串)
来源:互联网 发布:windows编程7 编辑:程序博客网 时间:2024/04/29 20:11
题型:简单题
题意:
将n个单词连成一句话后进行编码,每个单词之间加个“<3”(包括首尾),之后在这段字符串中的任意位置加上小写字母、数字、大于号>、小于号< 都视为合法。现在给出一个字符串b,问它是否合法。
分析:
先将一系列单词构成"<3word1<3word2<3word3<3"的形式,设为a字符串,长度为a_len ,然后拿a与b进行比较,如果碰到非法字符就直接跳出;设一个计数变量cnt,如果对应位置上字符不相等的,暂且算它是随意插入的合法字符, 然后在b上的扫描指针向后退以为,继续比较;如果相应位置相等了,cnt++,a和b上的扫描指针都向后退。最后看cnt与a_len是否相等。
代码:
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using namespace std;char a[1234567],b[1234567],c[123465];int main(){ int n; while(~scanf("%d",&n)){ int cnt=0; b[cnt++]='<'; b[cnt++]='3'; while(n--){ scanf("%s",c); int c_len=strlen(c); for(int i=0;i<c_len;i++){ b[cnt++]=c[i]; } b[cnt++]='<'; b[cnt++]='3'; } scanf("%s",a); int a_len=strlen(a); int count=0; bool flag=true; for(int i=0,j=0;i<a_len;i++){ if(a[i]==b[j]){ j++; count++; } else{ if((a[count]>='a'&&a[count]<='z')||(a[count]>='0'&&a[count]<='9')||(a[count]=='<')||(a[count]=='>')){ continue; } else{ flag=false; break; } } } if(!flag) printf("yes\n"); else{ if(count==cnt) printf("yes\n"); else printf("no\n"); } } return 0;}/*3iloveyou<3i<3love<23you<37iamnotmaininthefamily<3i<>3am<3the<3<main<3in<3the<3><3family<3*/
- Codeforces_358B_Dima and Text Messages(字符串)
- Codeforces 358B - Dima and Text Messages 字符串
- B. Dima and Text Messages---简单字符串处理
- B. Dima and Text Messages
- CF10月25日比赛。(Dima and Text Messages)
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces —— 358B Dima and Text Messages
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #208 (Div. 2) Dima and Text Messages
- Hust oj 2106 Genuine Messages(字符串)
- Some easy ways to send emails (via SMTP) and SMS text messages
- ON_NOTIFY and WM_NOTIFY Messages
- Receiving and Dispatching Messages
- Error Codes And Messages
- Messages and internationalization
- 消息和消息队列(Using Messages and Message Queues)
- About Messages and Message Queues
- iOS学习之sqlite的创建数据库,表,插入查看数据
- Struts2 验证码图片实例
- Hadoop学习笔记(六):Hadoop读写文件时内部工作机制
- SCTP程序感悟
- 数字信号处理相关
- Codeforces_358B_Dima and Text Messages(字符串)
- 手机操作网络模式
- static关键字详解
- Django TemplateView理解 Part2
- 你一笑 曾经让我傻半天
- java 获取IP
- Matlab矩阵和数组
- Android数据存储方式之SharedPreference
- 2014校招札记