B. Dima and Text Messages---简单字符串处理
来源:互联网 发布:淘宝联盟可以注销吗 编辑:程序博客网 时间:2024/05/16 17:01
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3word1<3word2<3 ... wordn<3.
Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.
Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.
The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.
In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.
3iloveyou<3i<3love<23you<3
yes
7iamnotmaininthefamily<3i<>3am<3the<3<main<3in<3the<3><3family<3
no
Please note that Dima got a good old kick in the pants for the second sample from the statement.
题目链接:http://codeforces.com/contest/358/problem/B
题目的意思是给你n个单词,在每个单词之间添加<3,在单词的任意地方可以添加小写字母,阿拉伯数字和< >两个符号,给出你一个字符串,问两个字符串是不是相等。
一开始想去掉给出字符串多余的字符,后来发现不行,我们可以把单词连接起来,然后判断就可以了。
代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;char s1[2000000],s2[2000000],s[200000];int main(){ int n; scanf("%d",&n); int cnt=0; s2[cnt++]='<'; s2[cnt++]='3'; while(n--){ scanf("%s",s); strcpy(s2+cnt,s); cnt+=strlen(s); s2[cnt++]='<'; s2[cnt++]='3'; } scanf("%s",s1); int s1_len=strlen(s1); int k=0; bool flag=true; for(int i=0,j=0;i<s1_len;i++){ if(s1[i]==s2[j]){ j++; k++; } else{ if((s1[i]>='a'&&s1[i]<='z')||(s1[i]>='0'&&s1[i]<='9')||(s1[i]=='<')||(s1[i]=='>')){ continue; } else{ flag=false; break; } } } if(k==cnt) printf("yes\n"); else printf("no\n"); return 0;}
- B. Dima and Text Messages---简单字符串处理
- B. Dima and Text Messages
- Codeforces 358B - 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
- CF10月25日比赛。(Dima and Text Messages)
- Codeforces Round #208 (Div. 2) Dima and Text Messages
- Codeforces_358B_Dima and Text Messages(字符串)
- B. Dima and Sequence
- 【简单题】-CF-390B-Inna, Dima and Song
- B. Little Dima and Equation
- B. Little Dima and Equation
- B. Little Dima and Equation
- B. Little Dima and Equation
- Codeforces Round #375 (Div. 2) B. Text Document Analysis(字符串处理,简单题目)
- Codeforces #262 (Div. 2) B. Little Dima and Equation(数学:简单)
- 查找树中两个节点的最低公共祖先
- 链表的知识点整理
- error: could not find or load main class
- SimpleDateFormat使用详解
- 如何让我们的ExtJs combobox支持模糊匹配
- B. Dima and Text Messages---简单字符串处理
- mysql报错:1130 -host 'localhost' is not allowed to connect to this mysql server
- 启动/停止rabbitmq及日志查看
- HDU-1232-畅通工程
- 数组的概念以及数组的常规属性
- while循环和doWhile循环
- 1-14文件系统、find
- c++ primer 5 第2章 变量和基本类型
- HDU6058 Kanade's sum【模拟】