mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.0 KiB
106 lines
2.0 KiB
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
|
||
5 years ago
|
"../lib"
|
||
|
"./correct"
|
||
5 years ago
|
)
|
||
|
|
||
|
type stuNode = NodeAddL
|
||
5 years ago
|
type solNode = correct.NodeAddL
|
||
5 years ago
|
|
||
|
func stuPushFront(node *stuNode, num int) *stuNode {
|
||
|
tmp := &stuNode{Num: num}
|
||
|
tmp.Next = node
|
||
|
return tmp
|
||
|
}
|
||
|
|
||
|
func stuNumToList(num int) *stuNode {
|
||
|
var res *stuNode
|
||
|
for num > 0 {
|
||
|
res = stuPushFront(res, num%10)
|
||
|
num /= 10
|
||
|
}
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
func stuListToNum(node *stuNode) int {
|
||
|
var n int
|
||
|
|
||
|
for tmp := node; tmp != nil; tmp = tmp.Next {
|
||
|
n = n*10 + tmp.Num
|
||
|
}
|
||
|
return n
|
||
|
}
|
||
|
|
||
|
func solPushFront(node *solNode, num int) *solNode {
|
||
|
tmp := &solNode{Num: num}
|
||
|
tmp.Next = node
|
||
|
return tmp
|
||
|
}
|
||
|
|
||
|
func printSol(node *solNode) string {
|
||
|
var result string
|
||
|
for tmp := node; tmp != nil; tmp = tmp.Next {
|
||
|
result += strconv.Itoa(tmp.Num)
|
||
|
if tmp.Next != nil {
|
||
|
result += "->"
|
||
|
}
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
func solNumToList(num int) *solNode {
|
||
|
var res *solNode
|
||
|
for num > 0 {
|
||
|
res = solPushFront(res, num%10)
|
||
|
num /= 10
|
||
|
}
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
func solListToNum(node *solNode) int {
|
||
|
var n int
|
||
|
|
||
|
for tmp := node; tmp != nil; tmp = tmp.Next {
|
||
|
n = n*10 + tmp.Num
|
||
|
}
|
||
|
return n
|
||
|
}
|
||
|
|
||
5 years ago
|
func compareNodes(stuResult *stuNode, solResult *solNode, num1 int) {
|
||
5 years ago
|
solList := printSol(solNumToList(num1))
|
||
|
if stuResult == nil && solResult == nil {
|
||
5 years ago
|
return
|
||
|
}
|
||
|
if stuResult != nil && solResult == nil {
|
||
5 years ago
|
stuNum := stuListToNum(stuResult)
|
||
5 years ago
|
lib.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n",
|
||
5 years ago
|
solList, stuNum, "")
|
||
5 years ago
|
}
|
||
|
if stuResult == nil && solResult != nil {
|
||
5 years ago
|
solNum := solListToNum(solResult)
|
||
5 years ago
|
lib.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n",
|
||
5 years ago
|
solList, "", solNum)
|
||
|
}
|
||
5 years ago
|
stuNum := stuListToNum(stuResult)
|
||
|
solNum := solListToNum(solResult)
|
||
|
if stuNum != solNum {
|
||
5 years ago
|
lib.Fatalf("\nChangeorder(%s) == %v instead of %v\n\n",
|
||
5 years ago
|
solList, stuNum, solNum)
|
||
5 years ago
|
}
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
5 years ago
|
func main() {
|
||
|
table := []int{1234567}
|
||
5 years ago
|
table = append(table, lib.MultRandIntBetween(0, 1000000000)...)
|
||
5 years ago
|
|
||
|
for _, arg := range table {
|
||
5 years ago
|
stuResult := Changeorder(stuNumToList(arg))
|
||
5 years ago
|
solResult := correct.Changeorder(solNumToList(arg))
|
||
5 years ago
|
|
||
5 years ago
|
compareNodes(stuResult, solResult, arg)
|
||
5 years ago
|
}
|
||
|
}
|