first commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package nxt;
|
||||
import java.util.Scanner;
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc=new Scanner(System.in);
|
||||
String s = sc.next();
|
||||
int n = s.length();
|
||||
int[] dpA = new int[n+1];
|
||||
int[] dpB = new int[n+1];
|
||||
for(int i=1; i<=n; i++){
|
||||
if(s.charAt(i-1)=='A'){
|
||||
dpA[i]=Math.min(dpA[i-1],dpB[i-1]+1);
|
||||
dpB[i]=Math.min(dpB[i-1]+1, dpA[i-1]+1);
|
||||
}else{
|
||||
dpA[i]=Math.min(dpA[i-1]+1,dpB[i-1]+1);
|
||||
dpB[i]=Math.min(dpB[i-1], dpA[i-1]+1);
|
||||
}
|
||||
}
|
||||
System.out.print(dpA[n]);
|
||||
sc.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user