// Copyright 漏 2010-12 Qtrac Ltd.
//
// This program or package and any associated files are licensed under the
// Apache License, Version 2.0 (the "License"); you may not use these files
// except in compliance with the License. You can get a copy of the License
// at: http://www.apache.org/licenses/LICENSE-2.0.
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 使用strings包中的Repeat函数
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
)
func main() {
if len(os.Args) == 1 {
fmt.Printf("usage: %s <whole-number>\n", filepath.Base(os.Args[0]))
os.Exit(1)
}
stringOfDigits := os.Args[1]
//增加 ****** 使用strings包中的Repeat函数
fmt.Println(strings.Repeat("*", len(stringOfDigits)*6))
/* for i := 0; i < len(stringOfDigits)*6; i++ {
fmt.Print("*")
}
fmt.Print("\n") */
for row := range bigDigits[0] {
line := ""
for _, digit := range stringOfDigits {
digit -= '0'
if 0 <= digit && digit <= 9 {
line += bigDigits[digit][row] + " "
} else {
log.Fatal("invalid whole number")
}
}
fmt.Println(line)
}
for i := 0; i < len(stringOfDigits)*6; i++ {
fmt.Print("*")
}
fmt.Print("\n")
}
var bigDigits = [][]string{
{" 000 ",
" 0 0 ",
"0 0",
"0 0",
"0 0",
" 0 0 ",
" 000 "},
{" 1 ", "11 ", " 1 ", " 1 ", " 1 ", " 1 ", "111"},
{" 222 ", "2 2", " 2 ", " 2 ", " 2 ", "2 ", "22222"},
{" 333 ", "3 3", " 3", " 33 ", " 3", "3 3", " 333 "},
{" 4 ", " 44 ", " 4 4 ", "4 4 ", "444444", " 4 ",
" 4 "},
{"55555", "5 ", "5 ", " 555 ", " 5", "5 5", " 555 "},
{" 666 ", "6 ", "6 ", "6666 ", "6 6", "6 6", " 666 "},
{"77777", " 7", " 7 ", " 7 ", " 7 ", "7 ", "7 "},
{" 888 ", "8 8", "8 8", " 888 ", "8 8", "8 8", " 888 "},
{" 9999", "9 9", "9 9", " 9999", " 9", " 9", " 9"},
}
test.ext 123
******************
1 222 333
11 2 2 3 3
1 2 3
1 2 33
1 2 3
1 2 3 3
111 22222 333
******************
有疑问加站长微信联系(非本文作者)