Skip to content

Instantly share code, notes, and snippets.

@sndnvaps
Last active December 15, 2015 12:48
Show Gist options
  • Save sndnvaps/5262767 to your computer and use it in GitHub Desktop.
Save sndnvaps/5262767 to your computer and use it in GitHub Desktop.
write timetable with golang
package main
import (
"fmt"
"os"
"strconv"
)
//tt := make(map[int] Timetable)
type Timetable struct {
weekday string
One [3]string
Two [3]string
Three [3]string
Four [3]string
}
//func print(Id int) 用于接收输入的参数 ,并输出一个星期中的任意一天的课程。
func print(Id int) {
tt := make(map[int] Timetable)
tt[1] = Timetable{"Monday",[3]string{"ZhengZhuan", "1-18", "5-401"}, [3]string{"Huobi","1-18", "3-303"}, [3]string{"Xingxi","4,8,12,16", "3-307"}, [3]string{"empty","empty","empty"}}
tt[2] = Timetable{"Tusday", [3]string{"English","1-18", "2-308"}, [3]string{"English Listening", "1-16", "1-508"}, [3]string{"empty","empty","empty"}, [3]string{"Kuiji", "1-6", "5-402"}}
tt[3] = Timetable{"Wednesday", [3]string{"Tiyu","1-15","Ground"}, [3]string{"MaoGai", "1-18","3-308"}, [3]string{"ZhengZhuan", "1-6", "5-401"}, [3]string{"Huobi","1-6","1-303"}}
tt[4] = Timetable{"Thusday", [3]string{"GouJiMaoYi","1-16","Z-704"}, [3]string{"English", "1-14", "2-308"}, [3]string{},[3]string{} }
tt[5] = Timetable{"Friday", [3]string{"Kuiji","1-18","5-402"}, [3]string{"Renli","2-13", "5-201"}, [3]string{}, [3]string{}}
tt[6] = Timetable{"Sat", [3]string{}, [3]string{}, [3]string{}, [3]string{} }
tt[7] = Timetable{"Sun", [3]string{}, [3]string{}, [3]string{}, [3]string{} }
if Id > 7 || Id < 1 { //当 输入的数字大于7 或者小于1的时候,输出错误
fmt.Println("Input Error\n")
} else {
timetable , ok := tt[Id]
if ok {
/*
fmt.Println(timetable.weekday)
fmt.Println(timetable.One)
fmt.Println(timetable.Two)
fmt.Println(timetable.Three)
fmt.Println(timetable.Four)
*/
fmt.Println(timetable.weekday,"\n",
timetable.One,"\n",
timetable.Two,"\n" ,
timetable.Three,"\n" ,
timetable.Four)
}
}
}
//main
func main() {
day := os.Args
if len(day) < 2 {
/*
fmt.Printf("Useage: Print the timetalbe of\n" +
"class 8, economi 2011")
fmt.Printf("example:timetalbe weekday\n")
fmt.Printf("weekday: 1, 2, 3, 4, 5, 6, 7\n")
*/
fmt.Printf("Usage: print timetable of\n" +
"Class 8, Economi 2011\n" +
"Example: timetable weekday\n" +
"weekday = 1,2,3,4,5,6,7\n")
} else {
Day, _ := strconv.Atoi(day[1])
print(Day)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment