/** * Created by com on 2016-01-14. */objectMain{defxor1(x1:Int,x2:Int,x3:Int,x4:Int):Int={valvalue=x1^x2^x3^x4value.toInt}defxor2(x1:Int,x2:Int,x3:Int):Int={valvalue=x1^x2^x3value.toInt}defx(value:Int):Int={if(value==0)1else0}defstringToInt(value:List[Int],acc:Int,sum:Int):Int=value.sizematch{case1=>sum+value.head*acccase_=>stringToInt(value.init,acc*2,sum+value.last*acc)}defsovle(input:Array[Int]):String={valx1=xor1(input(0),input(2),input(4),input(6))^xor2(input(2),input(4),input(6))valx2=xor1(input(1),input(2),input(5),input(6))^xor2(input(2),input(5),input(6))valx3=xor1(input(3),input(4),input(5),input(6))^xor2(input(4),input(5),input(6))valresult=List(x1,x2,x(input(2)),x3,input(4),input(5),input(6))valop=List(xor1(result(3),result(4),result(5),result(6)),xor1(result(1),result(2),result(5),result(6)),xor1(result(0),result(2),result(4),result(6)))valerrorBit=stringToInt(op,1,0)if(errorBit!=0){valresult2=result.patch(errorBit-1,Seq(x(result(errorBit-1))),1)List(result2(2),result2(4),result2(5),result2(6)).mkString}elseList(result(2),result(4),result(5),result(6)).mkString}defmain(args:Array[String]):Unit={valnum=scala.io.StdIn.readLine.toIntfor(i<-0untilnum){valvalue=scala.io.StdIn.readLineprintln(sovle(value.map(s=>s.toInt-48).toArray))}}}
lazysoul
8년 전