蓝桥杯最长子序列问题
public class lanqiao {
static boolean check(char[] chars,char a) {//判断T中字符是否存在于S中
for (int i = 0; i < chars.length; i++) {
if (a == chars[i]) {
return true;
}
}
return false;
}
public static void main(String[] args) {
int count=0;
Scanner scanner = new Scanner(System.in);
String S = new String();
String T = new String();
S = scanner.nextLine();
T = scanner.nextLine();
char[] c1 = S.toCharArray();
char[] c2 = T.toCharArray();
int s[] = new int[100];
for (int i = 0; i < c2.length; i++) {
for (int j=i;j<c2.length;j++){
if (check(c1,c2[j])==true){
count++;
}
else{
s[i]=count;
count=0;
break;
}
}
}
for (int k=0;k<s.length;k++){
count=Math.max(count,s[k]);
}
System.out.println(count);
}
}
这里虽然算法很冗余,但是好理解一点,(哭笑)