根本跳不动。。。本地几个案例都过了,在线就是不过。哎
var t,n,line,strList; t = Number(readline()); for (var i = 0; i < t; i++) {// t组数据 n = Number(readline()); strList = []; for (var j = 0; j < n; j++) {//每组n个字符串 strList.push(readline()); } var has = false; for (var m = 0; m < strList.length && !has; m++) {//n个字符串两两比较是否双生串 for (var n = m+1; n < strList.length; n++) { var s1 = strList[m], s2 = strList[n]; if (isDoubleBorn(s1,s2)) { has = true;//存在双生串 break; } } } if (has) console.log('Yeah\n');//存在双生串 else console.log('Sad\n'); } //判断双生串 function isDoubleBorn(s1, s2) { if (s1.length !== s2.length) return false; var front, tail,str,strReverse; for (var i = 1; i < s2.length; i++) { tail = s2.substring(0,i); front = s2.substring(i); str = front + tail; strReverse = str.split('').reverse().join(''); if (str === s1 || strReverse === s1) return true; } return false; }
------------------------------------------------------------------------------------------
另一个表达式
输入a = 4 - c b = 2 - d c = 2 - d 求 b - c
var nk,line,expList; while(line = readline()) { nk = line.trim().split(' ').map(i=>Number(i));//n在0下标,k在1下标 expList = []; for (var i = 0; i < nk[0]; i++) { line = readline().trim().replace(/\s/g,''); var a = line[0],b = line[line.length-1]; var c = line.substring(1,line.length-1); expList.push(line); expList.push(b + c + a);// a = 4 - b,获取反的b = 4 - a } var ok = false,res = 'cannot_answer'; var resList = []; for (var i = 0; i < nk[1]; i++) { line = readline().trim().replace(/\s/g,''); //a是表达式的b-d的b,,,b是b-d中的d var a = line[0], b = line[line.length-1]; var list1 = expList.filter(it=>{ return it[0] === a ; }); var list2 = expList.filter(it=>{ return it[0] === b; }); /st1是表达式以a开头的表达式 /st2是以b开头的表达式,,, //以构成a-b的查询 for (var n in list1) { for (var m in list2) { //对list1中每个对比list2,如果list1和list2结尾的变量相同,那么计算相减 //b = 2 - d //c = 4 - d //计算b-c,,,他们的d相同, var s1 = list1[n], s2 = list2[m]; if (s1[s1.length-1] === s2[s2.length-1]) { var num1 = s1.substring(2,s1.indexOf('-')); var num2 = s2.substring(2,s2.indexOf('-')); res = Number(num1) - Number(num2); ok = true; } } } if (ok) print(res+'\n'); else print('cannot_answer\n'); ok = false; } }
#笔试题目#