1195.滑る
質問リンク
1つの文字列を基準に、残りの1つを基準の末尾に移動し、最短の幅を求めます.
以下に示すように、例入力1でアクション・プロシージャを表示します.
1. step1
2. step2
3. step3
4. step4
5. step5
6. step6
7. step7
8. step8
9. step9

1.トラブルシューティング
1つの文字列を基準に、残りの1つを基準の末尾に移動し、最短の幅を求めます.
以下に示すように、例入力1でアクション・プロシージャを表示します.
1. step1

2. step2

3. step3

4. step4

5. step5

6. step6

7. step7

8. step8

9. step9

2.ソースコード
//킥다운
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
String a1 = sc.nextLine();
String a2 = sc.nextLine();
System.out.println(simulation(a1, a2));
}
private static int simulation(String a1, String a2) {
char[] a = a1.toCharArray();
char[] b = a2.toCharArray();
int a_idx = a.length;
int len = a.length + b.length;
while (a_idx >= 0) {
int c = 0;
int b_idx = 0;
int start = a_idx;
boolean check = true;
while (start < a.length && b_idx < b.length) {
if (a[start] == '2' && a[start] == b[b_idx]) {
check = false;
break;
}
c++;
start++;
b_idx++;
}
if (check)
len = Math.min(len, a.length + b.length - c);
a_idx--;
}
int b_idx = 1;
while (b_idx < b.length) {
int c = 0;
a_idx = 0;
int start = b_idx;
boolean check = true;
while (start < b.length && a_idx < a.length) {
if (b[start] == '2' && b[start] == a[a_idx]) {
check = false;
break;
}
c++;
start++;
a_idx++;
}
if (check)
len = Math.min(len, a.length + b.length - c);
b_idx++;
}
return len;
}
}
Reference
この問題について(1195.滑る), 我々は、より多くの情報をここで見つけました https://velog.io/@jms8732/1195.-킥다운テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol