codeforces J. Spelling Check
来源:互联网 发布:免费虚拟手机号软件 编辑:程序博客网 时间:2024/05/21 07:59
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?
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.
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;}
- codeforces J. Spelling Check
- Codeforces 39J Spelling Check hash
- CodeForces School Team Contest #1 (Winter Computer School 2010/11) J. Spelling Check
- CodeForces 44J Triminoes
- CodeForces - 630J Divisibility
- CodeForces-630 J. Divisibility
- Codeforces 630J Divisibility
- codeforces 589J
- codeforces 589J
- codeforces 730 J. Bottles
- codeforces 730J - Bottles
- codeforces 730 J Bottles
- Codeforces 630J
- Print Check CodeForces
- T9 Spelling
- Spelling Error
- Codeforces 589J. Cleaner Robot
- CodeForces 630J:Divisibility 【数学】
- LeetCode——1.Two Sum
- java实现日期转中文大写形式
- MFC中CArray类原理及其应用
- css盒子模型
- poj 1061 青蛙的约会
- codeforces J. Spelling Check
- 欧几里得算法及其扩展
- Java栈(数组实现)
- java中的实例初始化
- char,varchar的使用
- 学习网络编程推荐安装的软件
- Java栈(链式实现)
- Java解压zip文件
- 我和青春