Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- process.stdin.resume();
- process.stdin.setEncoding('utf8');
- var map=[];
- map[0] = Array.from('qwertyuiop')
- map[1] = Array.from('asdfghjkl')
- map[2] = Array.from('zxcvbnm')
- function isAdj(a,b){
- var posAR,posAC;
- [0,1,2].forEach(function(itemR,index,arr){
- if(map[itemR].indexOf(a)!=-1){
- posAR=itemR
- posAC=map[itemR].indexOf(a)
- }
- })
- var posBR,posBC;
- [0,1,2].forEach(function(itemR,index,arr){
- if(map[itemR].indexOf(b)!=-1){
- posBR=itemR
- posBC=map[itemR].indexOf(b)
- }
- })
- var q1=(Math.abs(posAR-posBR)<=1 && posAC-posBC==0)
- var q2=(Math.abs(posAC-posBC)<=1 && posAR-posBR==0)
- return q1 || q2
- }
- var arrLeft = Array.from('qwertasdfgzxcvb')
- process.stdin.on('data', function (chunk) {
- var line = chunk.toString();
- var mistake = 0
- var arrInput = Array.from(line)
- var prevHand = -1 //0=left
- arrInput.forEach(function(item, index, arr){
- var currentHand
- if(index!=0 && isAdj(arr[index],arr[index-1])){
- currentHand = prevHand
- if(arrLeft.indexOf(item)!=-1){//should be left
- if(currentHand==1){
- mistake++
- }
- }else{
- if(currentHand==0){
- mistake++
- }
- }
- }else{
- if(arrLeft.indexOf(item)!=-1){
- currentHand = 0
- }else{
- currentHand = 1
- }
- }
- prevHand=currentHand
- });
- console.log(mistake)
- });
Add Comment
Please, Sign In to add comment