Esempio n. 1
0
func main() {
	cgreader.RunStaticProgram(
		"../../input/mime_types_5.txt",
		"../../output/mime_types_5.txt",
		true,
		func(input <-chan string, output chan string) {
			var n, m int
			fmt.Sscanf(<-input, "%d", &n)
			fmt.Sscanf(<-input, "%d", &m)

			types := make(map[string]string)
			for i := 0; i < n; i++ {
				var key, value string
				fmt.Sscanf(<-input, "%s %s", &key, &value)
				types[strings.ToLower(key)] = value
			}

			for i := 0; i < m; i++ {
				var path string
				fmt.Sscanf(<-input, "%s", &path)
				path = strings.ToLower(path)

				if strings.Contains(path, ".") {
					sp := strings.Split(path, ".")
					if value, ok := types[sp[len(sp)-1]]; ok {
						output <- fmt.Sprintf("%s\n", value)
					} else {
						output <- fmt.Sprintln("UNKNOWN")
					}
				} else {
					output <- fmt.Sprintln("UNKNOWN")
				}
			}
		})
}
Esempio n. 2
0
func main() {
	cgreader.RunStaticProgram(
		"../input/super_computer_1.txt",
		"../output/super_computer_1.txt",
		true,
		&Program{})
}
Esempio n. 3
0
func main() {
	cgreader.RunStaticProgram(
		"<input_file>",
		"<output_file>",
		true,
		func(input <-chan string, output chan string) {
			// program logic
		})
}
Esempio n. 4
0
func CreateAndRunStaticProgram(programFile []byte, programInputFile, programOutputFile string) {
	if main, result := ParseStaticProgram(programFile); result {
		cgreader.RunStaticProgram(
			programInputFile,
			programOutputFile,
			isVerbose,
			CreateStaticFunction(main))
	}
}
Esempio n. 5
0
func main() {
	cgreader.RunStaticProgram(
		"../../input/ascii_4.txt",
		"../../output/ascii_4.txt",
		true,
		func(input <-chan string, output chan string) {
			var width, height int
			var text string

			fmt.Sscanln(<-input, &width)
			fmt.Sscanln(<-input, &height)
			fmt.Sscanln(<-input, &text)

			text = strings.ToUpper(text)

			ascii := make([]string, height)
			for i := 0; i < height; i++ {
				ascii[i] = <-input
			}

			lines := make([]string, height)
			for _, char := range text {
				character := int(char) - 65
				if character < 0 || character > 26 {
					character = 26
				}
				for i := range lines {
					position := character * width
					lines[i] += ascii[i][position : position+width]
				}
			}

			for _, line := range lines {
				output <- fmt.Sprintln(line)
			}
		})
}