Codeforces Round #422 B. Crossword solving
来源:互联网 发布:lol遇到一个网络问题 编辑:程序博客网 时间:2024/06/05 09:27
题目网址: Codeforces Round #422 B. Crossword solving
题意分析:
题意: 给字符串s, t; 求替换掉字符串s中最少的字符的次数使得s是t的子串
由于数据量不是很大, 暴力将 字符串s从t的首字符开始匹配, 匹配完一次, 再从t的下一个字符开始匹配. 双重循环, 求出最大匹配的位置, 即可求出最少需要替换次数
代码:
#include <iostream>using namespace std;const int SIZE = 1e3+5;char s[SIZE];char t[SIZE];int main(int argc, char const *argv[]){ int n, m; while (~scanf("%d %d", &n, &m)) { scanf("%s", s); scanf("%s", t); int pos = 0, suit = 0; int cnt; for (int i = 0; i <= m-n; ++i) { cnt = 0; int k = i; for (int j = 0; j < n; ++j, ++k) { if(s[j] == t[k]) ++cnt; } if(cnt > suit) { pos = i; suit = cnt; } } printf("%d\n", n-suit); for (int i = 0, k = pos; i < n; ++i, ++k) { if(s[i] != t[k]) printf("%d ", i+1); } printf("\n"); } return 0;}
阅读全文
1 0
- Codeforces Round #422 B. Crossword solving
- Codeforces Round #422 (Div. 2) B. Crossword solving
- Codeforces Round #422 (Div. 2) B. Crossword solving
- codeforces 822 B Crossword solving
- CodeForces 822B Crossword solving
- Codeforces 822B Crossword solving
- codeforces 822B(Crossword solving) Java
- codeforces 822-B. Crossword solving(vector)
- Codeforces822 B. Crossword solving
- B. Crossword solving
- B. Crossword solving
- CF422 div2 B. Crossword solving
- CF—822B Crossword solving
- Codeforces 90B-African Crossword
- Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)
- CodeForces 90B African Crossword【模拟】
- 0706 CF#822A-I'm bored with life #822B-Crossword solving
- Educational Codeforces Round 25 C Multi-judge Solving 贪心
- 探索ES6 Iterator(遍历器)
- 栈的应用
- Struts framework的工作原理和组件
- 深度学习的最好方案,FPGA或GPU?
- 讲课大师 把微信消息同步转发到企业微信中
- Codeforces Round #422 B. Crossword solving
- Python:斐波那契数列
- 洛谷P1308 统计单词数
- Activity被意外销毁状态保持
- Java 8速查表
- 从零开始:Mac OS下搭建 python3+selenium+firefox+pycharm 环境
- 电脑和交换机互连
- 写不完的BUG,纪念因为手滑写错代码而浪费的几个小时时间。
- Memcache查看列出所有key方法