codeforces 822B(Crossword solving) Java
来源:互联网 发布:好搜排名优化软件 编辑:程序博客网 时间:2024/05/21 22:32
字符串比较。暴力解决即可!!!
import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.InputStreamReader;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.util.Scanner;/** * 题意:最少需要替换几个 A 中的字符,使得 A 为 B 的子串,然后输出替换的个数和位置 * * @author tinydolphin * */public class Main { public static void main(String[] args) { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int strALength; int strBlength; int min; String strA; String strB; int count; int[] tempList; int[] list; while (in.hasNext()) { strALength = in.nextInt(); strBlength = in.nextInt(); strA = in.next(); strB = in.next(); // 初始化 tempList = new int[strALength + 1]; list = new int[strALength + 1]; min = Integer.MAX_VALUE; // 整段比较,维护替换个数的最小值。 for (int indexI = 0; indexI <= strBlength - strALength; indexI++) { count = 0; for (int indexJ = 0; indexJ < strALength; indexJ++) { if (strA.charAt(indexJ) != strB.charAt(indexI + indexJ)) { tempList[++count] = indexJ + 1; } } if (count < min) { min = count; System.arraycopy(tempList, 1, list, 1, count);// 最优数组复制方式 } } // 以下代码用作 输出结果 out.println(min); for (int index = 1; index <= min; index++) { out.print(list[index]); out.print(index == min ? "\n" : " "); } } out.flush(); }}
阅读全文
0 0
- codeforces 822B(Crossword solving) Java
- codeforces 822-B. Crossword solving(vector)
- codeforces 822 B Crossword solving
- CodeForces 822B Crossword solving
- Codeforces 822B Crossword solving
- Codeforces Round #422 B. Crossword solving
- CF—822B Crossword solving
- Codeforces822 B. Crossword solving
- B. Crossword solving
- B. Crossword solving
- Codeforces Round #422 (Div. 2) B. Crossword solving
- Codeforces Round #422 (Div. 2) B. Crossword solving
- CF422 div2 B. Crossword solving
- 0706 CF#822A-I'm bored with life #822B-Crossword solving
- Codeforces 90B-African Crossword
- CodeForces 90B African Crossword【模拟】
- CodeForces 721A One-dimensional Japanese Crossword(第三场)
- Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)
- 安装mysql步骤详情
- xml总结
- 判断某一天是一年的第几天
- 内部类
- 汽水瓶
- codeforces 822B(Crossword solving) Java
- spring HandlerExceptionResolver
- java爬虫教程02
- Android自定义UI
- java基础知识问题导航
- 面试题 7: 两个栈实现一个队列
- 消息提示-插件效果
- python3 爬虫环境准备 (三)-常用库的安装
- 获取空间hwnd