刘汝佳《算法竞赛入门经典(第二版)》习题(五)

刘汝佳《算法竞赛入门经典(第二版)》第三章习题(3-9~3-12)

习题3-9 子序列(UVa10340

输入两个字符串st,判断是否可以从t中删除0个或多个字符(其他字符顺序不变)。得到字符串s。例如,abcde可以得到bce,但无法得到dc

Input Specification

The input contains several testcases. Each is specified by two strings s, t of alphanumeric ASCII characters separated by whitespace. Input is terminated by EOF.

Output Specification

For each test case output, if s is a subsequence of t.

Sample Input

sequence subsequence

person compression

VERDI vivaVittorioEmanueleReDiItalia

caseDoesMatter CaseDoesMatter

Sample Output

Yes

 

Yes


解析

原题中规定时间限制2s,内存限制32MB,但没说输入字符串的长度限制,暂且按100000来做。这道题直接对st扫一遍即可。

#include <iostream>
#include <string>

using namespace std;

int main (void)
{
    string s,t;
    int i,j;
    while (cin >> s >> t)
    {
        for (i = 0, j = 0; i < s.size() && j < t.size();)
        {
            if (s[i] == t[j])
            {
                i++;
                j++;
            }
            else
                j++;
        }
        (i == s.size())?cout << "yes":cout << endl;
    }
    return 0;
}

习题3-10 盒子(ACM/ICPC NEERC 2004UVa1587

给定6个矩形的长和宽wihi1≤wihi≤1000),判断它们能否构成长方体的6个面。

Input 

Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet and contains two integer numbers w and h ( 1≤w

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值