2193: Newspaper Headline

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

 

意思:就是俩个字符串 s1,s2     s1可以是n个s1相加,然后 从s1中去掉一些字符,可以让这个字符串等于s2

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1,s2;
	cin>>s1>>s2;
	set<int>s[30];
	
	for(int i=0;i<s1.size();i++) s[s1[i]-'a'].insert(i);
	int flag=-1;
	int ans=1;
	for(int i=0;i<s2.size();i++){
		int t=s2[i]-'a';
		if(s[t].empty()){//如果在s1中找不到  那么输出-1 然后结束 
			puts("-1");
			return 0;
		} 
		set<int>::iterator it=s[t].upper_bound(flag);//看上一个是否超过了s1的长度 
		if(it==s[t].end()){//如果超过了,那么就加个s1 
			flag=-1;//重新定义flag值 ,然后更新为当前t在s1中的下标值 
			ans++;
		}
		flag=*(s[t].upper_bound(flag));//更新这个下标,看到哪了,留给下一次循环用来判断 
	} 
	printf("%d\n",ans);
	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值