-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.input any type.go
62 lines (54 loc) · 1.02 KB
/
4.input any type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bufio"
"os"
"strconv"
"fmt"
)
func Anytype(s string )interface{}{
i,err :=strconv.Atoi(s)
if err==nil{
return i
}
//i32,err := strconv.ParseInt(s,10,32)
//fmt.Println(i32," ",err)
//if err==nil{
// return i32
//}
i64,err := strconv.ParseInt(s,10,64)
if err==nil{
return i64
}
ui64,err := strconv.ParseUint(s,10,64)
if err==nil{
return ui64
}
f32,err := strconv.ParseFloat(s,32)
// fmt.Println(f32," ",err)
if err==nil{
return f32
}
f64,err := strconv.ParseFloat(s,64)
if err==nil{
return f64
}
com64,err := strconv.ParseComplex(s,64)
if err==nil{
return com64
}
com128,err := strconv.ParseComplex(s,128)
if err==nil{
return com128
}
b,err := strconv.ParseBool(s)// "1", "t", "T", "true", "TRUE", "True"//"0", "f", "F", "false", "FALSE", "False"
if err==nil{
return b
}
return s
}
func main(){
fmt.Printf("give any type of input (1 input): ")
x,_,_ :=bufio.NewReader(os.Stdin).ReadLine()
ans:=Anytype(string(x))
fmt.Printf("type : %T ,value : %v\n",ans,ans)
}