Scan接收整数和Scanf("%d",&i)接收整数有什么区别?
用Scanf有一个用例无法通过:
10 2000 1999 1998 1997 1996 1995 1994 1993 1992 1991 10 10 10 10 10 10 10 10 10 10
package main
import(
"fmt"
)
func main(){
for{
N:=0
_,err:=fmt.Scanln(&N)
if (err != nil || N<=0){
break
}
//fmt.Println(N)
var weightArray [100]int
var countArray [100]int
for i:=0;i<N;i++{
fmt.Scanf("%d",&weightArray[i])
}
for i:=0;i<N;i++{
fmt.Scanf("%d",&countArray[i])
}
count:=CalCount(weightArray[0:N],countArray[0:N])
if (count==1){
fmt.Println("==>",N)
}else if (count==12091){
fmt.Println("==>",N)
}
fmt.Println(count)
}
}
func CalCount(weightArray []int,countWeigtArray []int )int{
dic:=make(map[int]bool,0)
dic[0]=true
for i:=0;i<len(weightArray);i++{
for j:=0;j<countWeigtArray[i];j++{
tempDic:=copyMap(dic)
for k,_:=range tempDic{
dic[k+weightArray[i]]=true
}
}
}
return len(dic)
}
func copyMap(dic map[int]bool)map[int]bool{
tempDic:=make(map[int]bool,0)
for k,v:=range dic{
tempDic[k]=v
}
return tempDic
}



京公网安备 11010502036488号