模拟一试题javascript——右循环单词
readline = require('readline');
rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var n;
var index=0;
var arr= [];
rl.on('line',function(line){
switch (index){
case 0:
n=line.trim();
break;
default:
arr.push(line);
if(index==n){
var s = new Set();
for(var k=0;k<n;k++){
s.add(calc(arr[k]));
}
console.log(s.size);
index=-1;
arr=[];
n=0;
}
break;
}
index++;
})
function calc(a){
var v=[];
if(a.length!==undefined){
var tmp=a.substring(0);
for(var i = 0; i < a.length; i++){
for(var j = 0; j < a.length; j++){
tmp[j]=a[(j + i) %( a.length)];
}
v.push(tmp);
}
v.sort(function(a,b){
return a.localeCompare(b)});
}
return v[0];
}