题目链接: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 解题报告的更多相关文章

  1. codeforces A. Dima and Continuous Line 解题报告

    题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ...

  2. Codeforces Round #208 (Div. 2) B Dima and Text Messages

    #include <iostream> #include <algorithm> #include <string> using namespace std; in ...

  3. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  4. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  5. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  6. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  7. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  8. codeforces 505A. Mr. Kitayuta's Gift 解题报告

    题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...

  9. codeforces 499A.Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...

随机推荐

  1. list 内部方法

    代码 #list内部方法 l=['a','9','c','a','3','7'] print(dir(l)) l.append('v') print(l)#append(self, p_object) ...

  2. Java编程思想学习(七) 抽象类和接口

    1.抽象类和抽象方法 抽象方法:不完整的,仅有声明而没有方法体. abstract void f(); 抽象类:包含抽象方法的类.(若一个类包含一个或多个抽象方法,则该类必须限定为抽象的.) 1.用抽 ...

  3. 多线程练习(java)

    public class TestThread { public static void main(String[] args) { RandomNumber r=new RandomNumber() ...

  4. Java初学(一)

    一.初识Java 1.JVM:Java跨平台是基于JVM(Java虚拟机)的,JVM不是跨平台的,针对不同平台有对应的JVM软件 2.JRE:Java开发出来的软件如果要运行还需要在环境中安装JRE( ...

  5. php中mysql参数化查询

    $query = sprintf("SELECT * FROM Users where UserName='%s' and Password='%s'",mysql_real_es ...

  6. 网站性能Web压力测试工具webbench

    webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便. 1.适用系统:Linux 2.编译安装: wget http:/ ...

  7. nginx负载均衡器处理session共享的几种方法(转)

    1) 不使用session,换作cookie 能把session改成cookie,就能避开session的一些弊端,在从前看的一本J2EE的书上,也指明在集群系统中不能用session,否则惹出祸端来 ...

  8. jquery 使用方法<转载>

    jquery 使用方法 jQuery是目前使用最广泛的javascript函数库.据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库.微软公司 甚至把jQuery作为他们的官 ...

  9. Css transition

    CSS的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值. <!DOCTY ...

  10. 小白科普之JavaScript的数组

    一.与其他语言数据的比较    相同点:有序列表    不同点:js的数组的每一项可以保存任何类型的数据:数组的大小是可以动态调整的 二.数组创建的两种方法 1)  var colors = new ...