File tree Expand file tree Collapse file tree 4 files changed +74
-12
lines changed
Expand file tree Collapse file tree 4 files changed +74
-12
lines changed Original file line number Diff line number Diff line change 44 "encoding/xml"
55 "fmt"
66 "io"
7+ "log"
78 "os"
89)
910
@@ -57,14 +58,12 @@ type Bik struct {
5758
5859func checkErr (e error ) {
5960 if e != nil {
60- panic (e )
61+ log . Panic (e )
6162 }
6263}
6364
6465func init () {
6566 var err error
6667 devNull , err = os .OpenFile (os .DevNull , os .O_WRONLY , 0600 )
67- if err != nil {
68- panic (err )
69- }
68+ checkErr (err )
7069}
Original file line number Diff line number Diff line change 11package main
22
3- import "os"
3+ import (
4+ "bufio"
5+ "fmt"
6+ "log"
7+ "os"
8+ "strconv"
9+ )
10+
11+ // Example output:
12+ // var SupportedTaxDepartment = map[ConstitutionSubjectCode]TaxDepart{
13+ // 0: {
14+ // Name: "ФНС России",
15+ // },
16+ // 1: {
17+ // Name: "УФНС России по Республике Адыгея",
18+ // Branches: map[RegionTaxServiceNumber]string{
19+ // 1: "Межрайонная инспекция Федеральной налоговой службы №2 по Республике Адыгея",
20+ // 5: "Межрайонная инспекция Федеральной налоговой службы №1 по Республике Адыгея",
21+ // 7: "Межрайонная инспекция Федеральной налоговой службы №3 по Республике Адыгея",
22+ // },
23+ // },
24+ // }
425
526func main () {
6- file , err := os .Open ("input.txts " )
27+ file , err := os .Open ("input.txt " )
728 checkErr (err )
8- if err != nil {
9- panic (err )
10- }
29+
1130 defer func () {
1231 err = file .Close ()
1332 checkErr (err )
1433 }()
1534
35+ fmt .Println ("package main" , "\n " )
36+ fmt .Println ("var SupportedTaxDepartment = map[ConstitutionSubjectCode]TaxDepart{" )
37+
38+ scanner := bufio .NewScanner (file )
39+ var code int
40+
41+ var nextRegion bool
42+ for scanner .Scan () {
43+ row := scanner .Text ()
44+ code , err = strconv .Atoi (row )
45+ if err != nil {
46+ var output string
47+ if nextRegion {
48+ //fmt.Println("},")
49+ output += "Name: "
50+ }
51+ fmt .Println (output + "`" + row + "`," )
52+ if nextRegion {
53+ fmt .Println ("Branches: map[RegionTaxServiceNumber]string{" )
54+ }
55+
56+ nextRegion = false
57+ continue
58+ }
59+
60+ if code % 100 == 0 {
61+ fmt .Println ("}," )
62+ fmt .Println ("}," )
63+ fmt .Println (code / 100 , ": {" )
64+ nextRegion = true
65+ } else {
66+ fmt .Print (code % 100 , ":" )
67+ }
68+ }
69+
70+ fmt .Println ("}," ) // close branch map
71+ fmt .Println ("}," ) // close global map
72+ fmt .Println ("}" )
73+
74+ err = scanner .Err ()
75+ checkErr (err )
76+
1677}
1778
1879func checkErr (e error ) {
1980 if e != nil {
20- panic (e )
81+ log . Panic (e )
2182 }
2283}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
22
33import (
44 "fmt"
5+ "log"
56 "os"
67 "strings"
78 "unicode"
@@ -53,6 +54,6 @@ func excludeDigits(input string) string {
5354
5455func checkErr (e error ) {
5556 if e != nil {
56- panic (e )
57+ log . Panic (e )
5758 }
5859}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
22
33import (
44 "fmt"
5+ "log"
56 "os"
67 "strings"
78
@@ -39,6 +40,6 @@ func main() {
3940
4041func checkErr (e error ) {
4142 if e != nil {
42- panic (e )
43+ log . Panic (e )
4344 }
4445}
You can’t perform that action at this time.
0 commit comments