codeforces B. Dima and Text Messages 解题报告
题目链接:http://codeforces.com/problemset/problem/358/B
题目意思:给出n个单词(假设为word1,word2、word3...wordn)和一句test message,需要判断的是,这个 test message在去除一系列随机插入的英文字符后,是否满足<3word1<3word2<3 ... wordn<3 的结构。
首先要构造出一个参考序列,也就是<3word1<3word2<3 ... wordn<3的结构(总长度为 j )。
接着用test message (假设指向它元素的指针为 i )跟这个参考序列(指针为 k)作左到右依次比较,如果有相同的字符,那么k 向右移动一位,最后当整个test message扫描完后,判断k的值是否等于j ,若是,则符合参考序列的结构。
方法一:没有用string
Time: 31ms
Memory: 1200KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxin = 1e5 + ;
const int maxsave = 1e6 + ;
char a[maxin], b[maxin];
char s[maxsave]; int main()
{
int i, j, k, n, len1, len2;
while (scanf("%d", &n) != EOF)
{
j = ;
s[j++] = '<';
s[j++] = '';
while (n--)
{
scanf("%s", a);
len1 = strlen(a);
for (i = ; i < len1; i++)
s[j++] = a[i];
s[j++] = '<';
s[j++] = ''; // 构造一条对照序列
}
// for (i = 0; i < j; i++)
// printf("%c", s[i]);
// printf("\n\n");
getchar();
gets(b);
len1 = strlen(b);
for (k = , i = ; i < len1; i++)
{
if (b[i] == s[k])
k++;
}
if (k == j)
puts("yes");
else
puts("no");
}
return ;
}
方法二:用到string
Time:46ms
Memory:1000KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std; int main()
{
int i, j, n, len;
string str1, str2, tmp;
tmp = "<3";
while (scanf("%d", &n) != EOF)
{
str1.append(tmp);
for (i = ; i < n; i++)
{
cin >> str2;
str1.append(str2);
str1.append(tmp);
}
cin >> str2;
for (j = , i = ; i < str2.size(); i++)
{
if (str2[i] == str1[j])
j++;
}
if (j == str1.size())
puts("yes");
else
puts("no");
str1.clear();
}
return ;
}
codeforces B. Dima and Text Messages 解题报告的更多相关文章
- codeforces A. Dima and Continuous Line 解题报告
题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ...
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
#include <iostream> #include <algorithm> #include <string> using namespace std; in ...
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
- codeforces 433C. Ryouko's Memory Note 解题报告
题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...
- codeforces 556B. Case of Fake Numbers 解题报告
题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...
- codeforces 510B. Fox And Two Dots 解题报告
题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...
- codeforces 505A. Mr. Kitayuta's Gift 解题报告
题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...
- codeforces 499A.Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...
随机推荐
- Java获取各种常用时间方法大全
Java获取各种常用时间方法大全 package cc.javaweb.test; Java中文网,Java获取各种时间大全 import java.text.DateFormat; import j ...
- Bzoj3893 [Usaco2014 Dec]Cow Jog
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 302 Solved: 157 Description The cows are out exerci ...
- BZOJ 1066 POJ 2711 [SCOI2007]蜥蜴
与POJ 1815 Friendship类似,该题之前也做过 目前处于TLE状态.样例已经通过 1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec Memory Limit: ...
- ELF(Executable and Linkable Format)
目录 . 引言 . ELF文件格式 . ELF格式分析工具 0. 引言 0x1: ELF文件类型 ELF文件标准里把系统中采用ELF格式的文件归为以下几类 . 可重定位文件(Relocatable F ...
- IOS基础之 (八) Foundation框架
一 常用类 NSRange 范围,NSPoint 点,NSSize /CSSize 大小,CGRect 1 NSRange 1)NSRange是一种C语言结构用来帮助描述一系列的条款,包括一个起点位 ...
- jQueryEasyUI DateBox的基本使用
http://www.cnblogs.com/libingql/archive/2011/09/25/2189977.html 1.基本用法 代码: 1 2 3 4 5 6 7 8 9 10 11 1 ...
- 如何使用MASM来编译、连接、调试汇编语言
先声明下,本人绝非大虾,也只是菜鸟一个,写此文的目的只是为了加深我对知识的理解罢了.好,进入正题.我是把masm解压后发在D盘中的一个叫masm的文件里,在masm文件里新建个记事本(记事本功能是很强 ...
- spring mvc开发过程知识点记录
给一个客户做的一个小项目,需求就是输入类似一个短网址http://dd.yy/xxxx然后跳转到另外一个域名下的图书文件.(实际很多短网址站都提供API供调用吧,不过客户需求是他自己建立一个短网址服务 ...
- WPF 检测管理员权限
// 检查是否是管理员身份 private static void CheckAdministrator() { WindowsIdentity wi = null; try { wi = Windo ...
- ubuntu 14.04 安装mysql server初级教程
序,mysql数据库是开源的,被大多数企业所使用 目录 一.apt-get install 软件安装原理剖析二.安装mysql server三.配置和管理msyql 一.apt-get install ...