MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / charDiffIoUtil

Function charDiffIoUtil

executor/checker.go:111–195  ·  view source on GitHub ↗

比较每一个字符,但是忽略空白 Compare each char in buffer, but ignore the 'SpaceChar'

(useroutBuffer, answerBuffer []byte, useroutLen, answerLen int64)

Source from the content-addressed store, hash-verified

109// 比较每一个字符,但是忽略空白
110// Compare each char in buffer, but ignore the 'SpaceChar'
111func charDiffIoUtil(useroutBuffer, answerBuffer []byte, useroutLen, answerLen int64) (rel int, logtext string) {
112 var (
113 leftPos, rightPos int64 = 0, 0
114 maxLength = Max(useroutLen, answerLen)
115 leftByte, rightByte byte
116 )
117 for (leftPos < maxLength) && (rightPos < maxLength) && (leftPos < useroutLen) && (rightPos < answerLen) {
118 if leftPos < useroutLen {
119 leftByte = useroutBuffer[leftPos]
120 }
121 if rightPos < answerLen {
122 rightByte = answerBuffer[rightPos]
123 }
124
125 for leftPos < useroutLen && isSpaceChar(leftByte) {
126 leftPos++
127 if leftPos < useroutLen {
128 leftByte = useroutBuffer[leftPos]
129 } else {
130 leftByte = 0
131 }
132 }
133 for rightPos < answerLen && isSpaceChar(rightByte) {
134 rightPos++
135 if rightPos < answerLen {
136 rightByte = answerBuffer[rightPos]
137 } else {
138 rightByte = 0
139 }
140 }
141
142 if leftByte != rightByte {
143 return constants.JudgeFlagWA, fmt.Sprintf(
144 "WA: at leftPos=%d, rightPos=%d, leftByte=%d, rightByte=%d",
145 leftPos,
146 rightPos,
147 leftByte,
148 rightByte,
149 )
150 }
151 leftPos++
152 rightPos++
153 }
154
155 // 如果左游标没跑完
156 for leftPos < useroutLen {
157 leftByte = useroutBuffer[leftPos]
158 if !isSpaceChar(leftByte) {
159 return constants.JudgeFlagWA, fmt.Sprintf(
160 "WA: leftPos=%d, rightPos=%d, leftLen=%d, rightLen=%d",
161 leftPos,
162 rightPos,
163 useroutLen,
164 answerLen,
165 )
166 }
167 leftPos++
168 }

Callers 1

DiffTextMethod · 0.85

Calls 2

MaxFunction · 0.85
isSpaceCharFunction · 0.85

Tested by

no test coverage detected