A. Newspaper Headline

time limit per test:2 second

memory limit per test:256 megabytes

input:standard input

output:standard output

题目链接:https://codeforces.com/problemset/problem/91/A

A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a new word s2. It is considered that when Fangy erases some letter, there's no whitespace formed instead of the letter. That is, the string remains unbroken and it still only consists of lowercase Latin letters.

For example, the heading is "abc". If we take two such headings and glue them one to the other one, we get "abcabc". If we erase the letters on positions 1 and 5, we get a word "bcac".

Which least number of newspaper headings s1 will Fangy need to glue them, erase several letters and get word s2?

Input

The input data contain two lines. The first line contain the heading s1, the second line contains the word s2. The lines only consist of lowercase Latin letters (1 ≤ |s1| ≤ 104, 1 ≤ |s2| ≤ 106).

Output

If it is impossible to get the word s2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings s1, which Fangy will need to receive the word s2.

Examples

input

abc
xyz

output

-1

input

abcd
dabc

output

2

题意

把最少n个字符串s1拼起来,得到拼接好的字符串,删去若干字符,得到字符串s2

思路

按顺序寻找字符串s2的各个字符,因为s2的各个字符的相对位置在拼接的字符串中是不变的,所以一遍一遍在s1中寻找s2的各个字符即可,记录s1被寻找了几遍,即最少需要多少字符串s1

代码

#include <iostream>
#include <cstring>
using namespace std;char s1[10010],s2[1000010];
bool st1[26],st2[26];//st1、st2分别记录字符串s1、s2中哪些字符出现了int main()
{cin>>s1+1>>s2+1;int len1=strlen(s1+1);int len2=strlen(s2+1);for(int i=1;i<=len1;i++)st1[s1[i]-'a']=1;for(int j=1;j<=len2;j++)st2[s2[j]-'a']=1;for(int i=0;i<26;i++){if(st2[i]==1&&st1[i]==0)//如果s2中出现的字母s1中没有出现就输出-1{cout<<-1<<endl;return 0;}}int ans=1,j,i=1;while(1){for(j=1;j<=len1;j++){if(s1[j]==s2[i])i++;if(i>len2)goto here;}ans++;}here:cout<<ans<<endl;return 0;
}

Codeforces 91A Newspaper Headline相关推荐

  1. Codeforces 91A-Newspaper Headline

    Codeforces 91A Newspaper Headline 题目原址 [http://codeforces.com/problemset/problem/91/A] 题意 给两条字符串s1,s ...

  2. 算法偏见是什么_算法可能会使任何人(包括您)有偏见

    算法偏见是什么 在上一篇文章中,我们展示了当数据将情绪从动作中剥离时会发生什么 (In the last article, we showed what happens when data strip ...

  3. GO语言实现设计模式【全】

    文章目录 0.前言 1.责任链模式 概念 示例 登机过程 测试程序 运行结果 2.命令模式 概念 示例 电饭煲接收器 电饭煲命令 测试程序 运行结果 3.迭代器模式 概念 示例 班级成员 运行结果 4 ...

  4. Dubious Document

    问题 K: Dubious Document 时间限制: 1 Sec  内存限制: 128 MB 提交: 34  解决: 28 [提交][状态][讨论版][命题人:admin] 题目描述 Snuke ...

  5. 平常水题 - Atcoder 058 - C - 怪文書 / Dubious Document(字符串的处理)

    C - 怪文書 / Dubious Document                                                       Time limit : 2sec / ...

  6. ENG Note 1 : 英语写作模板

    英语写作模板:引入==>论证(论点.论据)==>呼应 第一段的写法:引入(第一句)-引起关注(第二句) Just as an old proverb says,where there is ...

  7. GO 语言实现设计模式【全】

    文章目录 0.前言 1.责任链模式 概念 示例 登机过程 测试程序 运行结果 2.命令模式 概念 示例 电饭煲接收器 电饭煲命令 测试程序 运行结果 3.迭代器模式 概念 示例 班级成员 运行结果 4 ...

  8. wi-fi以连接但无法上网_Wi-Fi无法扩展以弥合数字鸿沟

    wi-fi以连接但无法上网 Access to the Internet is poor across the nation. There's a Digital Divide that has so ...

  9. java判断日文_判断字符串是否含有日文

    日文字符的Unicode编码范围是: U+3040–U+309F: Hiragana U+30A0–U+30FF: Katakana U+4E00–U+9FBF: Kanji 所以我们只需要对每一个字 ...

最新文章

  1. 今日 Paper | 多人姿势估计;对话框语义分析;无监督语义分析;自然语言处理工具包等
  2. 2018 中国开源年度报告发布,阿里系独占鳌头
  3. Struts2框架学习Action命名空间创建方式
  4. java selenium验证元素是否存在
  5. 4分钟极速甩脂训练!抛开借口!繁忙族必备!
  6. hdu 3007(最小圆覆盖)
  7. Java获取成员变量构造函数信息
  8. MySQL的crash-safe原理详解
  9. HttpHandler和ashx使用Session 出现未初始化异常
  10. css内容过长显示省略号的几种解决方法
  11. vim插件ctags的安装和使用
  12. 【Ubuntu和本地电脑互传文件】
  13. 解决jdk证书问题-生成jssecacerts PKIX path building failed
  14. 亚洲前沿科技展望:人工智能与区块链的融合发展
  15. 在苹果Mac上怎样使用鼠标来放大图像?
  16. 关于软件开发中遇到的问题解决思路
  17. windows商店直接安装ubuntu子系统
  18. python3爬虫实战姚良_Python3.X 爬虫实战(缓存与持久化)
  19. linux mint 下载迅雷安装包,Linux Mint如何安装“微信、QQ、迅雷、WPS办公软件”等国内上瘾软件...
  20. RB-tree(红黑树)

热门文章

  1. Java开发工程师--面试题(珍藏版)
  2. CMOS图像传感器的曝光及读取时序
  3. 中国企业NAS行业市场供需与战略研究报告
  4. 股票查询小程序_以龙虎榜数据为例
  5. Batch Normalization论文读后感
  6. 抖音创作规范_抖音作品在内容规划是应该要注意的一些问题分析
  7. 斗地主老是输?一起用Python做个自动出牌器,欢乐豆蹭蹭涨!
  8. html 下拉组件被下面的组件挡住,div被select下拉框挡住了--5种解决方法
  9. LVOOP(一)、如何创建类、属性和方法
  10. LeetCode(Python)—— 相同的树(简单)