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 可以自动处理下一分钟,姑且理解 ...
随机推荐
- 【ZOJ 3897】Candy canes//Fiddlesticks
题 题意 给你一串数,a1...an,从左到右每次让一个数减小c,如果这个数小于c,那就减为0.第n个数减小后,又从第一个开始从左到右.如果这次某个数减小到0,那就改变方向,如果遇到已经是0的,就跳过 ...
- SpringMVC实现一个controller里面有多个方法
我们都知道,servlet代码一般来说只能在一个servlet中做判断去实现一个servlet响应多个请求, 但是springMVC的话还是比较方便的,主要有两种方式去实现一个controller里能 ...
- iOS代码工具箱再续
if (CGRectContainsPoint(self.menuView.frame, point)) { point = [self.view convertPoint:point toView ...
- resharper安装后,一不小心点错了(选择了object browser)
打开Resharper,选择Options,然后选择Tools中的External Sources,你的情况是选择了Navigation to Object Brower这一项了,换成第一个Defau ...
- App接口简介
- _stdcall与_cdecl(了解)
调用约定(Calling Convention)是指在程序设计语言中为了实现函数调用而建立的一种协议.这种协议规定了该语言的函数中的参数传送方式.参数是否可变和由谁来处理堆栈等问题.不同的语言定义了不 ...
- Spring实战学习笔记之SpEL表达式
在Spring XML配置文件中装配Bean的属性和构造参数都是静态的,而在运行期才知道装配的值,就可以使用SpEL实现 SpEL表达式的首要目标是通过计算获得某个值. ...
- Max批量导出工具
Max批量导出工具 http://www.paulneale.com/scripts/batchItMax/batchItMax.htm Scripts Batch It Max: Batch It ...
- php-fpm.conf两个至关重要的参数
这里规定了PHP-CGI的连接.发送和读取的时间,300秒足够用了,因此我的服务器很少出现504 Gateway Time-out这个错误.最关键的是php-fpm.conf的设置,这个会直接导致50 ...
- 解决Jquery对input file控件的onchange事件只生效一次的问题
如题,解决办法的代码如下: 1. $('#fileId').live('change',function(){ //逻辑添加.... }); 2. $('#fileId').change(functi ...