2

第一题男女特征BFS:
`var line;
var j = 0;
var arr = [];
while(line=readline()){

var a = [];//二维数组  

for(var k = 0; k<line; k++){

    a.push(readline());  
}  

}
function init(j) {

//深度优先搜索  

if(j===line){

    console.log(arr.join("-"));  
    return;  
}  
for(var i = 0;i<a[j].length;i++){  
    //堆的原理  

arr.push(aj);

    init(j+1);  
    arr.pop();  
}  

}
init(j);`

第二题:回文
`var line = readline();
function init(str) {

var result = [];
var res = 0;
for (var i = 1; i <= str.length; i++) {
    for (var j = 0; i + j <= str.length; j++) {
        result.push(str.substring(j, i + j));
    }
}
for (var k = 0; k < result.length; k++) {
    if (result[k].length > 1) {
        var len = result[k].length;
        var str = "";
        for(var t=len-1; t>=0;t--){
            str+=result[k][t];
        }
        if(str == result[k]){
            res = res + 1;
        }
    }
}
print(res);

}
init(line);`

第三题i am a boy去数组,再求最大子字符串:
`var line_1 = readline().split(' ');
var line_2 = readline().split(' ');
var line_3 = readline().split(' ');
function init(a,b,c) {

for(var i = 0;i<b.length;i++){
    if(a.indexOf(b[i]) === 0){
        b.splice(i,1);
    }
}
for(var j = 0;j<c.length;j++){
    if(a.indexOf(c[j]) !== -1){
        c.splice(j,1);
    }
}
var index = findSubStr(b.join(""),c.join(""));
if(b.length>c.length){
    print(b.length - index.length);
}else{
    print(c.length - index.length);
}

}
function findSubStr(s1,s2){

var S= "";
var sstr= "" ;
var L1=s1.length;
var L2=s2.length;
if (L1>L2){ var s3=s1;s1=s2,s2=s3,L1=s2.length;}
for ( var j=L1;j> 0 ;j--)
    for ( var i= 0 ;i<=L1-j;i++){
        sstr = s1.substr(i,j);
        if (s2.indexOf(sstr)>= 0 ) return sstr;
    }
return 0;

}
init(line_1,line_2,line_3);`


hdu_bomb
28 声望0 粉丝