CodeForces School Team Contest #1 (Winter Computer School 2010/11) J. Spelling Check

J. Spelling Check
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
abdrakadabra
abrakadabra
output
1
3
input
aa
a
output
2
1 2
input
competition
codeforces
output
0
 
        
哈希。。
/*
 *=====================
 *File Name:a.cpp
 *Author: qqspeed
 *Date: 2014年 07月 19日 星期六 18:13:18 CST
 *=====================
 */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

typedef long long ll;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define red(i,s,t) for(int i=s-1;i>=t;i--)
#define ree(i,now) for(int i=head[now];i!=-1;i=edge[i].next)
#define clr(a,v) memset(a,v,sizeof a)
#define L t<<1
#define R t<<1|1
#define MID int mid=(l+r)>>1
#define lowbit(x) (x&(-x))
#define SQR(a) ((a)*(a))

inline int input(){
	int ret=0;bool isN=0;char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') isN=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10+c-'0';
		c=getchar();
	}
	return isN?-ret:ret;
}

inline void output(int x){    
    if(x<0){    
        putchar('-');x=-x;    
    }    
    int len=0,data[11];    
    while(x){    
        data[len++]=x%10;x/=10;    
    }    
    if(!len)    data[len++]=0;    
    while(len--)   
        putchar(data[len]+48);    
    putchar('\n');  
}  


const ll base=26;
const ll mod=1000000007;
const int N=1000005;
ll p[N],h1[N],h2[N];
char a[N],b[N];
int l;
vector<int>ans;

inline void HASH(char *s,int l,ll *h){
	h[0]=s[0];
	rep(i,1,l){
		h[i]=h[i-1]+s[i]*p[i];
		h[i]%=mod;
	}
}

inline ll get(int s,int t,ll *h){
	if(s==0) return h[t];
	else return (h[t]-h[s-1]+mod)%mod;
}

inline bool ok(int a,int b,int c,int d){
	ll x=get(a,b,h1);
	ll y=get(c,d,h2);
	return x*p[c]%mod == y*p[a]%mod;
}

int main(){
	p[0]=1;
	rep(i,1,N) p[i]=p[i-1]*base%mod;
	scanf("%s%s",a,b);
	l=strlen(b);
	HASH(a,l+1,h1);
	HASH(b,l,h2);	
	rep(i,0,l+1){
		if(i==0){
			if(ok(1,l,0,l-1)) ans.push_back(i);
		}
		else if(i==l+1){
			if(ok(0,l-1,0,l-1)) ans.push_back(i);
		}
		else{
			if(ok(0,i-1,0,i-1) && ok(i+1,l,i,l-1)) ans.push_back(i);
		}
	}
	int s=ans.size();
	output(s);
	rep(i,0,s) printf("%d ",ans[i]+1);
	puts("");
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值