<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Go%2FFileIO</id>
	<title>Go/FileIO - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Go%2FFileIO"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Go/FileIO&amp;action=history"/>
	<updated>2026-06-20T00:38:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Go/FileIO&amp;diff=25842&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;&lt;pre&gt; package main  import ( 	&quot;bufio&quot; 	&quot;fmt&quot; 	&quot;log&quot; 	&quot;os&quot; 	&quot;sort&quot; 	&quot;strconv&quot; 	&quot;strings&quot; )  // readLines reads a whole file into memory // and returns a slice of its lines. fun...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Go/FileIO&amp;diff=25842&amp;oldid=prev"/>
		<updated>2018-12-16T06:02:36Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; package main  import ( 	&amp;quot;bufio&amp;quot; 	&amp;quot;fmt&amp;quot; 	&amp;quot;log&amp;quot; 	&amp;quot;os&amp;quot; 	&amp;quot;sort&amp;quot; 	&amp;quot;strconv&amp;quot; 	&amp;quot;strings&amp;quot; )  // readLines reads a whole file into memory // and returns a slice of its lines. fun...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
package main&lt;br /&gt;
&lt;br /&gt;
import (&lt;br /&gt;
	&amp;quot;bufio&amp;quot;&lt;br /&gt;
	&amp;quot;fmt&amp;quot;&lt;br /&gt;
	&amp;quot;log&amp;quot;&lt;br /&gt;
	&amp;quot;os&amp;quot;&lt;br /&gt;
	&amp;quot;sort&amp;quot;&lt;br /&gt;
	&amp;quot;strconv&amp;quot;&lt;br /&gt;
	&amp;quot;strings&amp;quot;&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
// readLines reads a whole file into memory&lt;br /&gt;
// and returns a slice of its lines.&lt;br /&gt;
func readLines(path string) ([]string, error) {&lt;br /&gt;
	file, err := os.Open(path)&lt;br /&gt;
	if err != nil {&lt;br /&gt;
		return nil, err&lt;br /&gt;
	}&lt;br /&gt;
	defer file.Close()&lt;br /&gt;
&lt;br /&gt;
	var lines []string&lt;br /&gt;
	scanner := bufio.NewScanner(file)&lt;br /&gt;
	for scanner.Scan() {&lt;br /&gt;
		lines = append(lines, scanner.Text())&lt;br /&gt;
	}&lt;br /&gt;
	return lines, scanner.Err()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// writeLines writes the lines to the given file.&lt;br /&gt;
func writeLines(lines []string, path string) error {&lt;br /&gt;
	file, err := os.Create(path)&lt;br /&gt;
	if err != nil {&lt;br /&gt;
		return err&lt;br /&gt;
	}&lt;br /&gt;
	defer file.Close()&lt;br /&gt;
&lt;br /&gt;
	w := bufio.NewWriter(file)&lt;br /&gt;
	for _, line := range lines {&lt;br /&gt;
		fmt.Fprintln(w, line)&lt;br /&gt;
	}&lt;br /&gt;
	return w.Flush()&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
func main() {&lt;br /&gt;
	filename := &amp;quot;A-small-practice.in&amp;quot;&lt;br /&gt;
	lines, err := readLines(filename)&lt;br /&gt;
	if err != nil {&lt;br /&gt;
		log.Fatalf(&amp;quot;readLines: %s&amp;quot;, err)&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	testCases, _ := strconv.Atoi(lines[0])&lt;br /&gt;
	var s []string&lt;br /&gt;
&lt;br /&gt;
	for i := 1; i &amp;lt; testCases*3; i += 3 {&lt;br /&gt;
		var v1 []string = strings.Split(lines[i+1], &amp;quot; &amp;quot;)&lt;br /&gt;
		var v2 []string = strings.Split(lines[i+2], &amp;quot; &amp;quot;)&lt;br /&gt;
		var v1i, v2i []int&lt;br /&gt;
		ans := 0&lt;br /&gt;
		tmpLen, _ := strconv.Atoi(lines[i])&lt;br /&gt;
		for j := 0; j &amp;lt; tmpLen; j++ {&lt;br /&gt;
			tmp, _ := strconv.Atoi(v1[j])&lt;br /&gt;
			v1i = append(v1i, tmp)&lt;br /&gt;
			tmp, _ = strconv.Atoi(v2[j])&lt;br /&gt;
			v2i = append(v2i, tmp)&lt;br /&gt;
		}&lt;br /&gt;
		sort.Sort(sort.IntSlice(v1i))&lt;br /&gt;
		sort.Sort(sort.Reverse(sort.IntSlice(v2i)))&lt;br /&gt;
&lt;br /&gt;
		for j := 0; j &amp;lt; tmpLen; j++ {&lt;br /&gt;
			ans += v1i[j] * v2i[j]&lt;br /&gt;
		}&lt;br /&gt;
		s = append(s, &amp;quot;Case #&amp;quot;+strconv.Itoa((i/3)+1)+&amp;quot;: &amp;quot;+strconv.Itoa(ans))&lt;br /&gt;
	}&lt;br /&gt;
	if err := writeLines(s, &amp;quot;A-small-practice.out&amp;quot;); err != nil {&lt;br /&gt;
		log.Fatalf(&amp;quot;Error!&amp;quot;, err)&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>