代码实现问题 CodeForces 822B
来源:互联网 发布:易云网络 西安 编辑:程序博客网 时间:2024/06/06 07:00
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?
Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found int as a substring. All the changes should be the following: Leha chooses one position in the strings and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear int="aabrbb" as a substring.
Guaranteed that the length of the string s doesn't exceed the length of the stringt. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found int as a substring. The symbol "?" should be considered equal to any other symbol.
The first line contains two integers n andm (1 ≤ n ≤ m ≤ 1000) — the length of the strings and the length of the string t correspondingly.
The second line contains n lowercase English letters — strings.
The third line contains m lowercase English letters — stringt.
In the first line print single integer k — the minimal number of symbols that need to be replaced.
In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.
Input
3 5
abc
xaybz
Output
22 3
Input
4 10
abcd
ebceabazcd
Output
1
2
题意:第一个字符串中替换几个字符可以在第二个字符串中找到 输出最小替换数 以及替换位置
#include<stdio.h>#include<string.h>char a[1005],b[1005];int ans[1005];int main(){int n,m;while(~scanf("%d%d",&n,&m)){scanf("%s",a);scanf("%s",b);int min = 10000;int count = 0;memset(ans,0,sizeof(ans));for(int i = 0; i <= (m-n);i++){count = 0;for(int j = 0; j < n; j++){if(a[j]!=b[i+j]){count++;}}if(min > count){min = count;memset(ans,0,sizeof(ans));for(int j = 0; j < n; j++){if(a[j]!=b[i+j]){ans[j]=1;}}}}printf("%d\n",min);for(int i = 0; i < n; i++){if(ans[i] == 1)printf("%d ",i+1);}printf("\n");}}
- 代码实现问题 CodeForces 822B
- Codeforces 158B(贪心问题)
- [CodeForces 490B]Queue[实现]
- 代码实现问题 [CodeForces-893A] [Problem A]
- B-树代码实现
- B树实现代码
- codeforces 651B B. Beautiful Paintings(贪心JAVA代码)
- codeforces 126B kmp串匹配问题
- [CodeForces 577B]Modulo Sum[实现][数学]
- codeforces 822 B Crossword solving
- CodeForces 822B Crossword solving
- Codeforces 822B Crossword solving
- SQLite B+树实现代码
- SQLite B+树实现代码
- codeforces B
- codeforces B
- codeforces B
- codeforces B
- PG 创建库指定字符集
- 八荣八耻 《IT版》《Java版》
- 正则表达式
- 一步一步开始FPGA逻辑设计
- python中socket初识
- 代码实现问题 CodeForces 822B
- 远程jvm监控
- 激活函数
- android studio快捷键
- Oracle中to_char()函数的用法(转)
- 《PL/SQL的HelloWorld》
- 拷贝构造函数什么时候调用?
- 一、初读java编程思想前四章
- 常用css样式