codeforces J. Spelling Check

Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?

Input

The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.

Output

In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.

哈希水过,万分震惊,将字符串改成数字,仅次而已

 

# include <stdio.h>
# include <string.h>
# include <vector>
using namespace std;
typedef long long int ll;
ll f1[1000010], f2[1000010], s1[1000010], s2[1000010];
char fs[1000010], ss[1000010];
vector<int> ans;
const ll B=100000007;
int main(){
    ll  i, j, k;
	scanf("%s", fs+1);
	scanf("%s", ss+1);
	ll length1=strlen(fs+1), length2=strlen(ss+1);
	for(i=1; i<=length1; i++){
		f1[i]=f1[i-1]*B+fs[i];
	}
	for(i=length1; i>=1; i--){
		f2[i]=f2[i+1]*B+fs[i];
	}
	for(i=1; i<=length2; i++){
		s1[i]=s1[i-1]*B+ss[i];
	}
	for(i=length2; i>=1; i--){
		s2[i]=s2[i+1]*B+ss[i];
	}
	for(i=1; i<=length1; i++){
		if(f1[i-1]==s1[i-1]&&f2[i+1]==s2[i]){
			ans.push_back(i);
		}
	}
	printf("%d\n", ans.size());
	for(i=0; i<ans.size(); i++){
		i==ans.size()-1?(printf("%d", ans[i])):(printf("%d ", ans[i]));
	}
	return 0;
}
 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值