diff --git a/AdvancedLevel_C++/1067. Sort with Swap(0,*) (25) .cpp b/AdvancedLevel_C++/1067. Sort with Swap(0,i) (25) .cpp similarity index 99% rename from AdvancedLevel_C++/1067. Sort with Swap(0,*) (25) .cpp rename to AdvancedLevel_C++/1067. Sort with Swap(0,i) (25) .cpp index ffbbb59..b516e2a 100644 --- a/AdvancedLevel_C++/1067. Sort with Swap(0,*) (25) .cpp +++ b/AdvancedLevel_C++/1067. Sort with Swap(0,i) (25) .cpp @@ -21,4 +21,4 @@ int main() { } cout << cnt; return 0; -} \ No newline at end of file +} diff --git "a/BasicLevel_Golang/1001. \345\256\263\346\255\273\344\272\272\344\270\215\345\201\277\345\221\275\347\232\204(3n+1)\347\214\234\346\203\263 (15).go" "b/BasicLevel_Golang/1001. \345\256\263\346\255\273\344\272\272\344\270\215\345\201\277\345\221\275\347\232\204(3n+1)\347\214\234\346\203\263 (15).go" new file mode 100644 index 0000000..2251a85 --- /dev/null +++ "b/BasicLevel_Golang/1001. \345\256\263\346\255\273\344\272\272\344\270\215\345\201\277\345\221\275\347\232\204(3n+1)\347\214\234\346\203\263 (15).go" @@ -0,0 +1,16 @@ +package main + +import "fmt" + +func main() { + var n, i int + fmt.Scanln(&n) + for ; n > 1; i++ { + if n%2 == 0 { + n = n / 2 + } else { + n = (3*n + 1) / 2 + } + } + fmt.Println(i) +} diff --git "a/BasicLevel_Golang/1002. \345\206\231\345\207\272\350\277\231\344\270\252\346\225\260 (20).go" "b/BasicLevel_Golang/1002. \345\206\231\345\207\272\350\277\231\344\270\252\346\225\260 (20).go" new file mode 100644 index 0000000..fb877ec --- /dev/null +++ "b/BasicLevel_Golang/1002. \345\206\231\345\207\272\350\277\231\344\270\252\346\225\260 (20).go" @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "strconv" +) + +func main() { + num := map[rune]string{ + '0': "ling", + '1': "yi", + '2': "er", + '3': "san", + '4': "si", + '5': "wu", + '6': "liu", + '7': "qi", + '8': "ba", + '9': "jiu", + } + var ( + n string + sum int + ) + //n = "1234567890987654321123456789" + fmt.Scanln(&n) + for _, k := range n { + sum = sum + int(k) - 48 + } + str := strconv.Itoa(sum) + for i, k := range str { + if i == len(str)-1 { + fmt.Printf("%s", num[k]) + break + } + fmt.Printf("%s ", num[k]) + } +} diff --git "a/BasicLevel_Golang/1003. \346\210\221\350\246\201\351\200\232\350\277\207\357\274\201(20).go" "b/BasicLevel_Golang/1003. \346\210\221\350\246\201\351\200\232\350\277\207\357\274\201(20).go" new file mode 100644 index 0000000..0904860 --- /dev/null +++ "b/BasicLevel_Golang/1003. \346\210\221\350\246\201\351\200\232\350\277\207\357\274\201(20).go" @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" +) + +func main() { + var num int + var str string + fmt.Scanf("%d\n", &num) + for i := 0; i < num; i++ { + var ( + pos int + count [3]int + ) + fmt.Scanln(&str) + //str = "APAAATAA" + for _, v := range str { + if v == 'A' { + count[pos]++ + } else if v == 'P' && pos == 0 { + pos = 1 + } else if v == 'T' && pos == 1 { + pos = 2 + } else { + break + } + } + if pos == 2 && count[1] != 0 && count[2] == count[1]*count[0] { + fmt.Println("YES") + } else { + fmt.Println("NO") + } + } +} diff --git "a/BasicLevel_Golang/1004 \346\210\220\347\273\251\346\216\222\345\220\215 (20).go" "b/BasicLevel_Golang/1004 \346\210\220\347\273\251\346\216\222\345\220\215 (20).go" new file mode 100644 index 0000000..686614a --- /dev/null +++ "b/BasicLevel_Golang/1004 \346\210\220\347\273\251\346\216\222\345\220\215 (20).go" @@ -0,0 +1,37 @@ +package main + +import "fmt" + +type student struct { + name string + id string + grade int +} + +func main() { + var ( + snum int + stu []student + first, last int + ) + fmt.Scanln(&snum) + for i := 0; i < snum; i++ { + var ( + tname string + tid string + tgrade int + ) + fmt.Scanln(&tname, &tid, &tgrade) + stu = append(stu, student{tname, tid, tgrade}) + } + + for k, v := range stu { + if v.grade > stu[first].grade { + first = k + } else if v.grade < stu[last].grade { + last = k + } + } + fmt.Println(stu[first].name, stu[first].id) + fmt.Println(stu[last].name, stu[last].id) +} diff --git "a/BasicLevel_Golang/1005. \347\273\247\347\273\255(3n+1)\347\214\234\346\203\263 (25).go" "b/BasicLevel_Golang/1005. \347\273\247\347\273\255(3n+1)\347\214\234\346\203\263 (25).go" new file mode 100644 index 0000000..d7b0957 --- /dev/null +++ "b/BasicLevel_Golang/1005. \347\273\247\347\273\255(3n+1)\347\214\234\346\203\263 (25).go" @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "sort" +) + +func main() { + var ( + num int + series []int + cover = map[int]int{} + tmp int + result []int + ) + fmt.Scanln(&num) + for i := 0; i < num; i++ { + fmt.Scanf("%d", &tmp) + series = append(series, tmp) + for tmp > 1 { + if tmp%2 == 0 { + tmp = tmp / 2 + } else { + tmp = (3*tmp + 1) / 2 + } + if cover[tmp] == 1 { + break + } else { + cover[tmp] = 1 + } + } + } + sort.Ints(series) + for i := 0; i < len(series); i++ { + if cover[series[i]] == 1 { + continue + } + result = append(result, series[i]) + } + for i := len(result) - 1; i > 0; i-- { + fmt.Printf("%d ", result[i]) + } + fmt.Printf("%d", result[0]) + +} diff --git "a/BasicLevel_Golang/1006. \346\215\242\344\270\252\346\240\274\345\274\217\350\276\223\345\207\272\346\225\264\346\225\260 (15).go" "b/BasicLevel_Golang/1006. \346\215\242\344\270\252\346\240\274\345\274\217\350\276\223\345\207\272\346\225\264\346\225\260 (15).go" new file mode 100644 index 0000000..a067168 --- /dev/null +++ "b/BasicLevel_Golang/1006. \346\215\242\344\270\252\346\240\274\345\274\217\350\276\223\345\207\272\346\225\264\346\225\260 (15).go" @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" +) + +func main() { + var ( + num int + n []int + ) + fmt.Scanln(&num) + for i := 0; i < 3; i++ { + n = append(n, num%10) + num = num / 10 + } + for i := 0; i < n[2]; i++ { + fmt.Printf("B") + } + for i := 0; i < n[1]; i++ { + fmt.Printf("S") + } + for i := 0; i < n[0]; i++ { + fmt.Printf("%d", i+1) + } +} diff --git "a/BasicLevel_Golang/1007. \347\264\240\346\225\260\345\257\271\347\214\234\346\203\263 (20).go" "b/BasicLevel_Golang/1007. \347\264\240\346\225\260\345\257\271\347\214\234\346\203\263 (20).go" new file mode 100644 index 0000000..81ea77a --- /dev/null +++ "b/BasicLevel_Golang/1007. \347\264\240\346\225\260\345\257\271\347\214\234\346\203\263 (20).go" @@ -0,0 +1,31 @@ +package main + +import "fmt" + +func isprime(a int) bool { + for i := 2; i*i <= a; i++ { + if a%i == 0 { + return false + } + } + return true +} + +func main() { + var ( + num int + old = 3 + count int + ) + fmt.Scanln(&num) + for i := 5; i <= num; i = i + 2 { + + if isprime(i) { + if i-old == 2 { + count++ + } + old = i + } + } + fmt.Println(count) +} diff --git "a/BasicLevel_Golang/1008. \346\225\260\347\273\204\345\205\203\347\264\240\345\276\252\347\216\257\345\217\263\347\247\273\351\227\256\351\242\230 (20).go" "b/BasicLevel_Golang/1008. \346\225\260\347\273\204\345\205\203\347\264\240\345\276\252\347\216\257\345\217\263\347\247\273\351\227\256\351\242\230 (20).go" new file mode 100644 index 0000000..b7e363d --- /dev/null +++ "b/BasicLevel_Golang/1008. \346\225\260\347\273\204\345\205\203\347\264\240\345\276\252\347\216\257\345\217\263\347\247\273\351\227\256\351\242\230 (20).go" @@ -0,0 +1,23 @@ +package main + +import "fmt" + +func main() { + var ( + n, m int + arr = []int{} + ) + fmt.Scanln(&n, &m) + for i := 0; i < n; i++ { + var tmp int + fmt.Scanf("%d", &tmp) + arr = append(arr, tmp) + } + for j := 0; j < m; j++ { + arr = append(arr[n-1:], arr[:n-1]...) + } + for i := 0; i < n-1; i++ { + fmt.Printf("%d ", arr[i]) + } + fmt.Printf("%d", arr[n-1]) +} diff --git "a/BasicLevel_Golang/1009. \350\257\264\345\217\215\350\257\235 (20).go" "b/BasicLevel_Golang/1009. \350\257\264\345\217\215\350\257\235 (20).go" new file mode 100644 index 0000000..dbd0dab --- /dev/null +++ "b/BasicLevel_Golang/1009. \350\257\264\345\217\215\350\257\235 (20).go" @@ -0,0 +1,20 @@ +package main + +import "fmt" + +func main() { + var ( + str = []string{} + s string + n int + ) + n, _ = fmt.Scanf("%s", &s) + for n == 1 { + str = append(str, s) + n, _ = fmt.Scanf("%s", &s) + } + for i := len(str) - 1; i > 0; i-- { + fmt.Printf("%s ", str[i]) + } + fmt.Printf("%s", str[0]) +} diff --git "a/BasicLevel_Golang/1010. \344\270\200\345\205\203\345\244\232\351\241\271\345\274\217\346\261\202\345\257\274 (25).go" "b/BasicLevel_Golang/1010. \344\270\200\345\205\203\345\244\232\351\241\271\345\274\217\346\261\202\345\257\274 (25).go" new file mode 100644 index 0000000..955061e --- /dev/null +++ "b/BasicLevel_Golang/1010. \344\270\200\345\205\203\345\244\232\351\241\271\345\274\217\346\261\202\345\257\274 (25).go" @@ -0,0 +1,24 @@ +package main + +import "fmt" + +func main() { + var ( + a, b int + flag int + ) + input, _ := fmt.Scanf("%d %d", &a, &b) + for input == 2 { + if b != 0 { + if flag == 1 { + fmt.Printf(" ") + } + fmt.Printf("%d %d", a*b, b-1) + flag = 1 + } + input, _ = fmt.Scanf("%d %d", &a, &b) + } + if flag == 0 { + fmt.Printf("0 0") + } +} diff --git "a/BasicLevel_Golang/1011. A+B\345\222\214C (15).go" "b/BasicLevel_Golang/1011. A+B\345\222\214C (15).go" new file mode 100644 index 0000000..869d139 --- /dev/null +++ "b/BasicLevel_Golang/1011. A+B\345\222\214C (15).go" @@ -0,0 +1,15 @@ +package main + +import "fmt" + +func main() { + var ( + a, b, c int64 + num int + ) + fmt.Scanln(&num) + for i := 0; i < num; i++ { + fmt.Scanf("%d %d %d", &a, &b, &c) + fmt.Printf("Case #%d: %t\n", i+1, a+b > c) + } +} diff --git "a/BasicLevel_Golang/1012. \346\225\260\345\255\227\345\210\206\347\261\273 (20).go" "b/BasicLevel_Golang/1012. \346\225\260\345\255\227\345\210\206\347\261\273 (20).go" new file mode 100644 index 0000000..0f4c9a0 --- /dev/null +++ "b/BasicLevel_Golang/1012. \346\225\260\345\255\227\345\210\206\347\261\273 (20).go" @@ -0,0 +1,62 @@ +package main + +import "fmt" + +func main() { + var ( + tmp, num int + sum [5]int + count [5]int + ) + fmt.Scanf("%d", &num) + for i := 0; i < num; i++ { + fmt.Scanf("%d", &tmp) + switch tmp % 5 { + case 0: + if tmp%2 == 0 { + count[0]++ + sum[0] = sum[0] + tmp + } + case 1: + count[1]++ + if count[1]%2 == 1 { + sum[1] = sum[1] + tmp + } else { + sum[1] = sum[1] - tmp + } + case 2: + count[2]++ + case 3: + sum[3] = sum[3] + tmp + count[3]++ + case 4: + count[4]++ + if tmp > sum[4] { + sum[4] = tmp + } + } + } + //fmt.Println(count,sum) + for i := 0; i < 4; i++ { + if count[i] == 0 { + fmt.Printf("N ") + continue + } + switch i { + case 0: + fmt.Printf("%d ", sum[0]) + case 1: + fmt.Printf("%d ", sum[1]) + case 2: + fmt.Printf("%d ", count[2]) + case 3: + fmt.Printf("%.1f ", float32(sum[3])/float32(count[3])) + } + } + if count[4] != 0 { + fmt.Printf("%d", sum[4]) + } else { + fmt.Printf("N") + } + +} diff --git "a/BasicLevel_Golang/1013. \346\225\260\347\264\240\346\225\260 (20).go" "b/BasicLevel_Golang/1013. \346\225\260\347\264\240\346\225\260 (20).go" new file mode 100644 index 0000000..48d3d4b --- /dev/null +++ "b/BasicLevel_Golang/1013. \346\225\260\347\264\240\346\225\260 (20).go" @@ -0,0 +1,35 @@ +package main + +import "fmt" + +func isPrime(num int) bool { + for i := 2; i*i <= num; i++ { + if num%i == 0 { + return false + } + } + return true +} + +func main() { + var ( + p, m, n int + count int + ) + fmt.Scanln(&m, &n) + for p = 2; count < m-1; p++ { + if isPrime(p) { + count++ + } + } + for ; count < n; p++ { + if isPrime(p) { + count++ + if (count+1-m)%10 == 0 || count == n { + fmt.Printf("%d\n", p) + } else { + fmt.Printf("%d ", p) + } + } + } +} diff --git "a/BasicLevel_Golang/1014. \347\246\217\345\260\224\346\221\251\346\226\257\347\232\204\347\272\246\344\274\232 (20).go" "b/BasicLevel_Golang/1014. \347\246\217\345\260\224\346\221\251\346\226\257\347\232\204\347\272\246\344\274\232 (20).go" new file mode 100644 index 0000000..97ce7c4 --- /dev/null +++ "b/BasicLevel_Golang/1014. \347\246\217\345\260\224\346\221\251\346\226\257\347\232\204\347\272\246\344\274\232 (20).go" @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + "unicode" +) + +func main() { + var ( + str [4]string + i, j int + week = map[byte]string{ + 'A': "MON", + 'B': "TUE", + 'C': "WED", + 'D': "THU", + 'E': "FRI", + 'F': "SAT", + 'G': "SUN", + } + ) + + for i = 0; i < 4; i++ { + fmt.Scanln(&str[i]) + } + + for i = 0; i < len(str[0]) && i < len(str[1]); i++ { + if str[0][i] == str[1][i] && (str[0][i] <= 'G' && str[0][i] >= 'A') { + fmt.Printf("%s ", week[str[0][i]]) + break + } + } + i = i + 1 + for ; i < len(str[0]) && i < len(str[1]); i++ { + if str[0][i] == str[1][i] { + if unicode.IsDigit(rune(str[0][i])) { + fmt.Printf("%02d:", str[0][i]-'0') + break + } + if str[0][i] >= 'A' && str[0][i] <= 'N' { + fmt.Printf("%02d:", str[0][i]-'A'+10) + break + } + } + } + for j = 0; j < len(str[2]) && j < len(str[3]); j++ { + if str[2][j] == str[3][j] && unicode.IsLetter(rune(str[2][j])) { + fmt.Printf("%02d", j) + } + } +} diff --git "a/BasicLevel_Golang/1015. \345\276\267\346\211\215\350\256\272 (25).go" "b/BasicLevel_Golang/1015. \345\276\267\346\211\215\350\256\272 (25).go" new file mode 100644 index 0000000..7a810b8 --- /dev/null +++ "b/BasicLevel_Golang/1015. \345\276\267\346\211\215\350\256\272 (25).go" @@ -0,0 +1,68 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "sort" + "strconv" + "strings" +) + +//L is student level weight +const L = 100000000000000 + +//S is student grade weight +const S = 100000000000 + +//D is student id weight +const D = 100000000 + +func main() { + var ( + n, l, h int + id, de, cai int + sum, level, count int + student []int64 + ) + fmt.Scanln(&n, &l, &h) + inputReader := bufio.NewReader(os.Stdin) + for i := 0; i < n; i++ { + s, _ := inputReader.ReadString('\n') + t := strings.Fields(s) + id, _ = strconv.Atoi(string(t[0])) + de, _ = strconv.Atoi(string(t[1])) + cai, _ = strconv.Atoi(string(t[2])) + //fmt.Scanln(&id, &de, &cai) + if de >= l && cai >= l { + sum = de + cai + if de >= h && cai >= h { + level = 4 + } else if de >= h && cai < h { + level = 3 + } else if de < h && cai < h && de >= cai { + level = 2 + } else { + level = 1 + } + tmp := level*L + sum*S + de*D + D - id + student = append(student, int64(tmp)) + count++ + } + } + + sort.SliceStable(student, func(i, j int) bool { + return student[i] > student[j] + }) + + fmt.Println(count) + buf := bufio.NewWriter(os.Stdout) + for i := 0; i < count; i++ { + id = int(D - student[i]%D) + sum = int(student[i] % L / S) + de = int(student[i] % S / D) + cai = sum - de + buf.WriteString(fmt.Sprintf("%d %d %d\n", id, de, cai)) + } + buf.Flush() +} diff --git "a/BasicLevel_Golang/1016. \351\203\250\345\210\206A+B (15).go" "b/BasicLevel_Golang/1016. \351\203\250\345\210\206A+B (15).go" new file mode 100644 index 0000000..ebb498f --- /dev/null +++ "b/BasicLevel_Golang/1016. \351\203\250\345\210\206A+B (15).go" @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "math" +) + +func main() { + var ( + a, b string + da, db rune + counta, countb int + pa, pb int + ) + fmt.Scanln(&a, &da, &b, &db) + for _, v := range a { + //fmt.Println(v) + if v == da+48 { + pa += int(da) * int(math.Pow10(counta)) + counta++ + } + } + for _, v := range b { + if v == db+48 { + pb += int(db) * int(math.Pow10(countb)) + countb++ + } + } + fmt.Println(pa + pb) +} diff --git "a/BasicLevel_Golang/1017. A\351\231\244\344\273\245B (20).go" "b/BasicLevel_Golang/1017. A\351\231\244\344\273\245B (20).go" new file mode 100644 index 0000000..e6bc0c9 --- /dev/null +++ "b/BasicLevel_Golang/1017. A\351\231\244\344\273\245B (20).go" @@ -0,0 +1,25 @@ +package main + +import "fmt" + +func main() { + var ( + a string + b int + q []rune + r int + ) + fmt.Scanln(&a, &b) + for _, v := range a { + n := r*10 + int(v-'0') + q = append(q, rune(n/b)) + r = n % b + } + for k, v := range q { + if k == 0 && v == 0 && len(q) != 1 { + continue + } + fmt.Printf("%v", v) + } + fmt.Printf(" %d", r) +} diff --git "a/BasicLevel_Golang/1018. \351\224\244\345\255\220\345\211\252\345\210\200\345\270\203 (20).go" "b/BasicLevel_Golang/1018. \351\224\244\345\255\220\345\211\252\345\210\200\345\270\203 (20).go" new file mode 100644 index 0000000..29304cf --- /dev/null +++ "b/BasicLevel_Golang/1018. \351\224\244\345\255\220\345\211\252\345\210\200\345\270\203 (20).go" @@ -0,0 +1,53 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func findMax(a [3]int) int { + var max, index int + for k, v := range a { + if v > max { + max = v + index = k + } + } + return index +} + +func main() { + var ( + n int + jiawin, yiwin int + jia, yi [3]int + str = "BCJ" + ) + // 用fmt读取输入会有测试点超时 + inputReader := bufio.NewReader(os.Stdin) + fmt.Scanln(&n) + for i := 0; i < n; i++ { + s, _ := inputReader.ReadString('\n') + t := strings.Fields(s) + if t[0] == "B" && t[1] == "C" { + jia[0]++ + } else if t[0] == "B" && t[1] == "J" { + yi[2]++ + } else if t[0] == "C" && t[1] == "B" { + yi[0]++ + } else if t[0] == "C" && t[1] == "J" { + jia[1]++ + } else if t[0] == "J" && t[1] == "B" { + jia[2]++ + } else if t[0] == "J" && t[1] == "C" { + yi[1]++ + } + } + jiawin = jia[0] + jia[1] + jia[2] + yiwin = yi[0] + yi[1] + yi[2] + fmt.Println(jiawin, n-jiawin-yiwin, yiwin) + fmt.Println(yiwin, n-jiawin-yiwin, jiawin) + fmt.Printf("%c %c", str[findMax(jia)], str[findMax(yi)]) +} diff --git "a/BasicLevel_Golang/1019. \346\225\260\345\255\227\351\273\221\346\264\236 (20).go" "b/BasicLevel_Golang/1019. \346\225\260\345\255\227\351\273\221\346\264\236 (20).go" new file mode 100644 index 0000000..bd4c21e --- /dev/null +++ "b/BasicLevel_Golang/1019. \346\225\260\345\255\227\351\273\221\346\264\236 (20).go" @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "sort" + "strconv" +) + +func main() { + var ( + n string + chu, bchu int + result int + ) + fmt.Scanln(&n) + //n = "1111" + for result != 6174 && n != "0" { + var a []int + if len(n) == 1 { + a = append(a, 0, 0, 0) + } else if len(n) == 2 { + a = append(a, 0, 0) + } else if len(n) == 3 { + a = append(a, 0) + } + for _, v := range n { + a = append(a, int(v-'0')) + } + sort.Ints(a) + bchu = a[3]*1000 + a[2]*100 + a[1]*10 + a[0] + chu = a[0]*1000 + a[1]*100 + a[2]*10 + a[3] + result = bchu - chu + fmt.Printf("%04d - %04d = %04d\n", bchu, chu, result) + n = strconv.Itoa(result) + } + +} diff --git "a/BasicLevel_Golang/1020. \346\234\210\351\245\274 (25).go" "b/BasicLevel_Golang/1020. \346\234\210\351\245\274 (25).go" new file mode 100644 index 0000000..ceee7a1 --- /dev/null +++ "b/BasicLevel_Golang/1020. \346\234\210\351\245\274 (25).go" @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "sort" +) + +type mooncake struct { + storage, price, unitprice float64 +} + +func main() { + var ( + n int + d float64 + cake = []mooncake{} + total float64 + ) + fmt.Scanln(&n, &d) + for i := 0; i < n; i++ { + var s float64 + fmt.Scanf("%f", &s) + cake = append(cake, mooncake{s, 0, 0}) + } + for i := 0; i < n; i++ { + var p float64 + fmt.Scanf("%f", &p) + cake[i].price, cake[i].unitprice = p, p/cake[i].storage + } + sort.SliceStable(cake, func(i, j int) bool { + return cake[i].unitprice > cake[j].unitprice + }) + + for i := 0; i < n && d != 0; i++ { + if cake[i].storage <= d { + total += cake[i].price + } else { + total += cake[i].unitprice * d + break + } + d = d - cake[i].storage + } + fmt.Printf("%.2f", total) +} diff --git "a/BasicLevel_Golang/1021. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 (15).go" "b/BasicLevel_Golang/1021. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 (15).go" new file mode 100644 index 0000000..723d025 --- /dev/null +++ "b/BasicLevel_Golang/1021. \344\270\252\344\275\215\346\225\260\347\273\237\350\256\241 (15).go" @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" +) + +func main() { + var ( + n string + num [10]int + ) + fmt.Scanln(&n) + //n = "100311" + for _, v := range n { + num[int(v-'0')]++ + } + for k, v := range num { + if v == 0 { + continue + } + fmt.Printf("%d:%d\n", k, v) + } +} diff --git "a/BasicLevel_Golang/1022. D\350\277\233\345\210\266\347\232\204A+B (20).go" "b/BasicLevel_Golang/1022. D\350\277\233\345\210\266\347\232\204A+B (20).go" new file mode 100644 index 0000000..21bc2a6 --- /dev/null +++ "b/BasicLevel_Golang/1022. D\350\277\233\345\210\266\347\232\204A+B (20).go" @@ -0,0 +1,24 @@ +package main + +import "fmt" + +func main() { + var ( + a, b, d int + sum int + num []int + ) + fmt.Scanln(&a, &b, &d) + sum = a + b + if sum == 0 { + fmt.Print(0) + return + } + for sum != 0 { + num = append(num, sum%d) + sum /= d + } + for i := len(num) - 1; i >= 0; i-- { + fmt.Printf("%d", num[i]) + } +} diff --git "a/BasicLevel_Golang/1023. \347\273\204\344\270\252\346\234\200\345\260\217\346\225\260 (20).go" "b/BasicLevel_Golang/1023. \347\273\204\344\270\252\346\234\200\345\260\217\346\225\260 (20).go" new file mode 100644 index 0000000..de3e97e --- /dev/null +++ "b/BasicLevel_Golang/1023. \347\273\204\344\270\252\346\234\200\345\260\217\346\225\260 (20).go" @@ -0,0 +1,22 @@ +package main + +import "fmt" + +func main() { + var a [10]int + fmt.Scanln(&a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9]) + for i := 1; i < 10; i++ { + if a[i] != 0 { + fmt.Printf("%d", i) + a[i]-- + break + } + } + for k, v := range a { + if v != 0 { + for j := 0; j < v; j++ { + fmt.Printf("%d", k) + } + } + } +} diff --git "a/BasicLevel_Golang/1024. \347\247\221\345\255\246\350\256\241\346\225\260\346\263\225 (20).go" "b/BasicLevel_Golang/1024. \347\247\221\345\255\246\350\256\241\346\225\260\346\263\225 (20).go" new file mode 100644 index 0000000..e7f185a --- /dev/null +++ "b/BasicLevel_Golang/1024. \347\247\221\345\255\246\350\256\241\346\225\260\346\263\225 (20).go" @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + "math" + "strconv" +) + +func main() { + var ( + s string + i int + ) + fmt.Scanln(&s) + //s = "-1.234000E+05" + //s = "-1.2E+10" + for s[i] != 'E' { + i++ + } + t := s[1:i] + n, _ := strconv.ParseFloat(s[i+1:], 64) + //fmt.Println(n) + //fmt.Println(reflect.TypeOf(t)) + if s[0] == '-' { + fmt.Printf("%c", s[0]) + } + if n < 0 { + fmt.Printf("0.") + for j := 0; j < int(math.Abs(n)-1); j++ { + fmt.Printf("0") + } + for j := 0; j < len(t); j++ { + if t[j] != '.' { + fmt.Printf("%c", t[j]) + } + } + } else { + fmt.Printf("%c", t[0]) + var count, j int + for j = 2; j < len(t) && count < int(n); j++ { + fmt.Printf("%c", t[j]) + count++ + } + if j == len(t) { + for k := 0; k < int(n)-count; k++ { + fmt.Printf("0") + } + } else { + fmt.Printf(".") + for k := j; k < len(t); k++ { + fmt.Printf("%c", t[k]) + } + } + } + +} diff --git "a/BasicLevel_Golang/1025. \345\217\215\350\275\254\351\223\276\350\241\250 (25).go" "b/BasicLevel_Golang/1025. \345\217\215\350\275\254\351\223\276\350\241\250 (25).go" new file mode 100644 index 0000000..c27a6a1 --- /dev/null +++ "b/BasicLevel_Golang/1025. \345\217\215\350\275\254\351\223\276\350\241\250 (25).go" @@ -0,0 +1,45 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +type node struct { + data string + next string +} + +func main() { + var ( + address string + n, k, n1 int + memory = map[string]node{} + list = []string{} + ) + fmt.Scanln(&address, &n1, &k) + inputReader := bufio.NewReader(os.Stdin) + for i := 0; i < n1; i++ { + s, _ := inputReader.ReadString('\n') + t := strings.Fields(s) + memory[t[0]] = node{t[1], t[2]} + } + for ; memory[address].next != "-1"; n++ { + list = append(list, address) + address = memory[address].next + } + n, list = n+1, append(list, address) + for i := 0; i < n-n%k; i += k { + for j, k := i, i+k-1; j < k; j, k = j+1, k-1 { + list[j], list[k] = list[k], list[j] + } + } + buf := bufio.NewWriter(os.Stdout) + for i := 0; i < n-1; i++ { + buf.WriteString(fmt.Sprintf("%s %s %s\n", list[i], memory[list[i]].data, list[i+1])) + } + buf.Flush() + fmt.Println(list[n-1], memory[list[n-1]].data, "-1") +} diff --git "a/BasicLevel_Golang/1026. \347\250\213\345\272\217\350\277\220\350\241\214\346\227\266\351\227\264(15).go" "b/BasicLevel_Golang/1026. \347\250\213\345\272\217\350\277\220\350\241\214\346\227\266\351\227\264(15).go" new file mode 100644 index 0000000..03be29f --- /dev/null +++ "b/BasicLevel_Golang/1026. \347\250\213\345\272\217\350\277\220\350\241\214\346\227\266\351\227\264(15).go" @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + var c1, c2 int + fmt.Scanln(&c1, &c2) + sum := (c2 - c1 + 50) / 100 + fmt.Printf("%02d:%02d:%02d", sum/3600, (sum%3600)/60, sum%60) +} diff --git "a/BasicLevel_Golang/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).go" "b/BasicLevel_Golang/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).go" new file mode 100644 index 0000000..1ba7098 --- /dev/null +++ "b/BasicLevel_Golang/1027. \346\211\223\345\215\260\346\262\231\346\274\217(20).go" @@ -0,0 +1,33 @@ +package main + +import "fmt" + +func main() { + var ( + N, n int + symbol string + ) + fmt.Scanln(&N, &symbol) + for n = 1; n*n <= (N+1)/2; n++ { + } + n-- + for i := n; i > 0; i-- { + for j := 0; j < n-i; j++ { + fmt.Printf(" ") + } + for k := 0; k < 2*i-1; k++ { + fmt.Printf("%s", symbol) + } + fmt.Printf("\n") + } + for i := 2; i <= n; i++ { + for j := 0; j < n-i; j++ { + fmt.Printf(" ") + } + for k := 0; k < 2*i-1; k++ { + fmt.Printf("%s", symbol) + } + fmt.Printf("\n") + } + fmt.Println(N - n*n*2 + 1) +} diff --git "a/BasicLevel_Golang/1028. \344\272\272\345\217\243\346\231\256\346\237\245(20).go" "b/BasicLevel_Golang/1028. \344\272\272\345\217\243\346\231\256\346\237\245(20).go" new file mode 100644 index 0000000..4dd82e8 --- /dev/null +++ "b/BasicLevel_Golang/1028. \344\272\272\345\217\243\346\231\256\346\237\245(20).go" @@ -0,0 +1,41 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +type person struct { + name string + birth string +} + +func main() { + var ( + N, count int + oldest, youngest string + maxbirth = "1814/09/06" + minbirth = "2014/09/06" + ) + fmt.Scanln(&N) + inputReader := bufio.NewReader(os.Stdin) + for i := 0; i < N; i++ { + input, _ := inputReader.ReadString('\n') + str := strings.Fields(input) + if str[1] >= "1814/09/06" && str[1] <= "2014/09/06" { + count++ + if str[1] >= maxbirth { + maxbirth, oldest = str[1], str[0] + } + if str[1] <= minbirth { + minbirth, youngest = str[1], str[0] + } + } + } + fmt.Printf("%d", count) + if count != 0 { + fmt.Printf(" %s %s", youngest, oldest) + } +} diff --git "a/BasicLevel_Golang/1029. \346\227\247\351\224\256\347\233\230(20).go" "b/BasicLevel_Golang/1029. \346\227\247\351\224\256\347\233\230(20).go" new file mode 100644 index 0000000..119aa21 --- /dev/null +++ "b/BasicLevel_Golang/1029. \346\227\247\351\224\256\347\233\230(20).go" @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + var ( + real, fake string + str []rune + ) + fmt.Scanf("%s\n%s", &real, &fake) + real, fake = strings.ToUpper(real), strings.ToUpper(fake) + for _, v := range real { + if strings.Index(fake, string(v)) == -1 && strings.Index(string(str), string(v)) == -1 { + str = append(str, v) + } + } + for _, v := range str { + fmt.Printf("%c", v) + } +} diff --git "a/BasicLevel_Golang/1030. \345\256\214\347\276\216\346\225\260\345\210\227(25).go" "b/BasicLevel_Golang/1030. \345\256\214\347\276\216\346\225\260\345\210\227(25).go" new file mode 100644 index 0000000..94721f6 --- /dev/null +++ "b/BasicLevel_Golang/1030. \345\256\214\347\276\216\346\225\260\345\210\227(25).go" @@ -0,0 +1,37 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "sort" + "strconv" + "strings" +) + +func main() { + var ( + N, p int + seq []int + count int + ) + fmt.Scanln(&N, &p) + inputReader := bufio.NewReader(os.Stdin) + input, _ := inputReader.ReadString('\n') + s := strings.Fields(input) + for _, v := range s { + num, _ := strconv.Atoi(v) + seq = append(seq, num) + } + sort.Ints(seq) + for i := 0; i < N; i++ { + for j := i + count; j < N; j++ { + if seq[j] <= seq[i]*p && (j-i+1) > count { + count = j - i + 1 + } else { + break + } + } + } + fmt.Println(count) +} diff --git "a/BasicLevel_Golang/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).go" "b/BasicLevel_Golang/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).go" new file mode 100644 index 0000000..b79abb0 --- /dev/null +++ "b/BasicLevel_Golang/1031. \346\237\245\351\252\214\350\272\253\344\273\275\350\257\201(15).go" @@ -0,0 +1,40 @@ +package main + +import "fmt" + +func isFake(id string) bool { + var ( + sum int + weight = [...]int{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2} + checkcode = [...]byte{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'} + ) + for i := 0; i < 17; i++ { + if id[i] < '0' || id[i] > '9' { + return true + } + sum += int(id[i]-'0') * weight[i] + } + z := sum % 11 + if checkcode[z] != id[17] { + return true + } + return false +} + +func main() { + var ( + N, flag int + id string + ) + fmt.Scanln(&N) + for i := 0; i < N; i++ { + fmt.Scanln(&id) + if isFake(id) { + fmt.Println(id) + flag = 1 + } + } + if flag == 0 { + fmt.Println("All passed") + } +} diff --git "a/BasicLevel_Golang/1032. \346\214\226\346\216\230\346\234\272\346\212\200\346\234\257\345\223\252\345\256\266\345\274\272(20).go" "b/BasicLevel_Golang/1032. \346\214\226\346\216\230\346\234\272\346\212\200\346\234\257\345\223\252\345\256\266\345\274\272(20).go" new file mode 100644 index 0000000..8605ded --- /dev/null +++ "b/BasicLevel_Golang/1032. \346\214\226\346\216\230\346\234\272\346\212\200\346\234\257\345\223\252\345\256\266\345\274\272(20).go" @@ -0,0 +1,32 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + var ( + N int + grade [100001]int + maxid, maxgrade int + ) + fmt.Scanln(&N) + inputReader := bufio.NewReader(os.Stdin) + for i := 0; i < N; i++ { + input, _ := inputReader.ReadString('\n') + t := strings.Fields(input) + id, _ := strconv.Atoi(t[0]) + g, _ := strconv.Atoi(t[1]) + grade[id] += g + } + for k, v := range grade { + if v > maxgrade { + maxid, maxgrade = k, v + } + } + fmt.Println(maxid, maxgrade) +} diff --git "a/BasicLevel_Golang/1033. \346\227\247\351\224\256\347\233\230\346\211\223\345\255\227(20).go" "b/BasicLevel_Golang/1033. \346\227\247\351\224\256\347\233\230\346\211\223\345\255\227(20).go" new file mode 100644 index 0000000..f0f7cb7 --- /dev/null +++ "b/BasicLevel_Golang/1033. \346\227\247\351\224\256\347\233\230\346\211\223\345\255\227(20).go" @@ -0,0 +1,38 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func main() { + var ( + bad, str string + flag int + ) + fmt.Scanln(&bad) + fmt.Scanln(&str) + + //在循环外判断可以减少时间复杂度 + if strings.Contains(bad, "+") { + flag = 1 + } + + //循环内如何使用fmt.Print系列函数输出,提交结果随机,最后一个测试点可能过可能不过 + buf := bufio.NewWriter(os.Stdout) + for _, v := range str { + if v >= 'A' && v <= 'Z' && flag == 1 { + continue + } + if v >= 'a' && v <= 'z' && strings.Contains(bad, strings.ToUpper(string(v))) { + continue + } + if strings.Contains(bad, string(v)) { + continue + } + buf.WriteString(string(v)) + } + buf.Flush() +} diff --git "a/BasicLevel_Golang/1034. \346\234\211\347\220\206\346\225\260\345\233\233\345\210\231\350\277\220\347\256\227(20).go" "b/BasicLevel_Golang/1034. \346\234\211\347\220\206\346\225\260\345\233\233\345\210\231\350\277\220\347\256\227(20).go" new file mode 100644 index 0000000..3207285 --- /dev/null +++ "b/BasicLevel_Golang/1034. \346\234\211\347\220\206\346\225\260\345\233\233\345\210\231\350\277\220\347\256\227(20).go" @@ -0,0 +1,120 @@ +package main + +import ( + "fmt" + "math" + "strconv" + "strings" +) + +//Gcd 最大公约数:辗转相除法 +func Gcd(x, y int64) int64 { + x = int64(math.Abs(float64(x))) + y = int64(math.Abs(float64(y))) + + var tmp int64 + for { + tmp = (x % y) + if tmp > 0 { + x = y + y = tmp + } else { + return y + } + } +} + +//Lcm 最小公倍数 +func Lcm(x, y int64) int64 { + return (x * y) / Gcd(x, y) +} + +//Add 分数加法 +func Add(a1, b1, a2, b2 int64) (c1, c2 int64) { + lcm := Lcm(b1, b2) + c1 = a1*(lcm/b1) + a2*(lcm/b2) + c2 = lcm + return c1, c2 +} + +//Sub 分数减法 +func Sub(a1, b1, a2, b2 int64) (c1, c2 int64) { + lcm := Lcm(b1, b2) + c1 = a1*(lcm/b1) - a2*(lcm/b2) + c2 = lcm + return c1, c2 +} + +//Mul 分数乘法 +func Mul(a1, b1, a2, b2 int64) (c1, c2 int64) { + gcd := Gcd(a1*a2, b1*b2) + c1 = a1 * a2 / gcd + c2 = b1 * b2 / gcd + return c1, c2 +} + +//Div 分数除法 +func Div(a1, b1, a2, b2 int64) (c1, c2 int64) { + c1 = a1 * b2 + c2 = a2 * b1 + if (c1 < 0 && c2 < 0) || (c1 > 0 && c2 < 0) { + c1, c2 = c1*(-1), c2*(-1) + } + return c1, c2 +} + +//Display 精简显示 +func Display(c1, c2 int64) string { + var flag int + var str []string + if c2 == 0 { + return "Inf" + } + if c1 == 0 { + return "0" + } + gcd := Gcd(c1, c2) + if c1 < 0 { + str = append(str, "(", "-") + flag = 1 + c1 *= (-1) + } + k := c1 / c2 + a, b := c1/gcd, c2/gcd + if k != 0 { + str = append(str, strconv.Itoa(int(k))) + } + if k != 0 && b != 1 { + str = append(str, " ") + } + if b != 1 { + str = append(str, strconv.Itoa(int(a%b)), "/", strconv.Itoa(int(b))) + } + if flag == 1 { + str = append(str, ")") + } + result := strings.Join(str, "") + return result +} + +func main() { + var m, n string + fmt.Scanln(&m, &n) + + str1 := strings.Split(m, "/") + a1, _ := strconv.Atoi(str1[0]) + b1, _ := strconv.Atoi(str1[1]) + str2 := strings.Split(n, "/") + a2, _ := strconv.Atoi(str2[0]) + b2, _ := strconv.Atoi(str2[1]) + c1 := Display(int64(a1), int64(b1)) + c2 := Display(int64(a2), int64(b2)) + s1, s2 := Add(int64(a1), int64(b1), int64(a2), int64(b2)) + fmt.Println(c1, "+", c2, "=", Display(s1, s2)) + d1, d2 := Sub(int64(a1), int64(b1), int64(a2), int64(b2)) + fmt.Println(c1, "-", c2, "=", Display(d1, d2)) + p1, p2 := Mul(int64(a1), int64(b1), int64(a2), int64(b2)) + fmt.Println(c1, "*", c2, "=", Display(p1, p2)) + q1, q2 := Div(int64(a1), int64(b1), int64(a2), int64(b2)) + fmt.Println(c1, "/", c2, "=", Display(q1, q2)) +} diff --git "a/BasicLevel_Golang/1035. \346\217\222\345\205\245\344\270\216\345\275\222\345\271\266(25).go" "b/BasicLevel_Golang/1035. \346\217\222\345\205\245\344\270\216\345\275\222\345\271\266(25).go" new file mode 100644 index 0000000..9338756 --- /dev/null +++ "b/BasicLevel_Golang/1035. \346\217\222\345\205\245\344\270\216\345\275\222\345\271\266(25).go" @@ -0,0 +1,89 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "sort" + "strconv" + "strings" +) + +func createIntSlice(str string) []int { + var intSlice []int + for _, v := range strings.Fields(str) { + tmp, err := strconv.Atoi(v) + if err == nil { + intSlice = append(intSlice, tmp) + } + } + return intSlice +} + +func searchInsertion(ori []int, mid []int) (bool, []int) { + var i, j int + for i = 0; i < len(ori)-1 && mid[i] <= mid[i+1]; i++ { + } + for j = i + 1; j < len(ori) && ori[j] == mid[j]; j++ { + } + sort.Ints(mid[:i+2]) + return j == len(ori), mid +} + +func merge(ori []int, mid []int) []int { + k,flag := 1,true + for flag { + flag = false + for i := 0;i < len(ori);i++ { + if ori[i] != mid[i] { + flag = true + } + } + k = k*2 + for i := 0; i < len(ori)/k;i++ { + sort.Ints(ori[i*k:(i+1)*k]) + } + sort.Ints(ori[len(ori)/k*k:len(ori)]) + } + return ori +} + +func main() { + var ( + N int + original, middle []int + ) + fmt.Scanln(&N) + scanner := bufio.NewScanner(os.Stdin) + for i := 1; i <= 2 && scanner.Scan(); i++ { + switch i { + case 1: + original = createIntSlice(scanner.Text()) + case 2: + middle = createIntSlice(scanner.Text()) + } + } + //N = 10 + //ori = "3 1 2 8 7 5 9 4 0 6" + //mid = "1 2 3 4 5 7 8 9 0 6 " + copyMiddle := make([]int, len(middle)) + copy(copyMiddle, middle) + if truth, next := searchInsertion(original, middle); truth { + fmt.Println("Insertion Sort") + for k, v := range next { + if k != 0 { + fmt.Printf(" ") + } + fmt.Printf("%d", v) + } + } else { + fmt.Println("Merge Sort") + result := merge(original, copyMiddle) + for k, v := range result { + if k != 0 { + fmt.Printf(" ") + } + fmt.Printf("%d", v) + } + } +} diff --git "a/BasicLevel_Golang/1036. \350\267\237\345\245\245\345\267\264\351\251\254\344\270\200\350\265\267\347\274\226\347\250\213(15).go" "b/BasicLevel_Golang/1036. \350\267\237\345\245\245\345\267\264\351\251\254\344\270\200\350\265\267\347\274\226\347\250\213(15).go" new file mode 100644 index 0000000..f26fdbc --- /dev/null +++ "b/BasicLevel_Golang/1036. \350\267\237\345\245\245\345\267\264\351\251\254\344\270\200\350\265\267\347\274\226\347\250\213(15).go" @@ -0,0 +1,31 @@ +package main + +import ( + "fmt" +) + +func main() { + var ( + N int + C string + ) + fmt.Scanln(&N, &C) + for i := 0; i < N; i++ { + fmt.Printf("%s", C) + } + fmt.Printf("\n") + for i := 0; i < N/2+N%2-2; i++ { + for j := 0; j < N; j++ { + if j == 0 { + fmt.Printf("%s", C) + } else if j == N-1 { + fmt.Printf("%s\n", C) + } else { + fmt.Printf(" ") + } + } + } + for i := 0; i < N; i++ { + fmt.Printf("%s", C) + } +} diff --git "a/BasicLevel_Golang/1037. \345\234\250\351\234\215\346\240\274\346\262\203\350\214\250\346\211\276\351\233\266\351\222\261\357\274\21020\357\274\211.go" "b/BasicLevel_Golang/1037. \345\234\250\351\234\215\346\240\274\346\262\203\350\214\250\346\211\276\351\233\266\351\222\261\357\274\21020\357\274\211.go" new file mode 100644 index 0000000..d844a72 --- /dev/null +++ "b/BasicLevel_Golang/1037. \345\234\250\351\234\215\346\240\274\346\262\203\350\214\250\346\211\276\351\233\266\351\222\261\357\274\21020\357\274\211.go" @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "strconv" + "strings" +) + +func main() { + var ( + P, A string + back int + ) + fmt.Scanln(&P, &A) + shoud := money(P) + real := money(A) + if real < shoud { + fmt.Printf("-") + back = shoud - real + } else { + back = real - shoud + } + fmt.Printf("%d.%d.%d", back/(17*29), back%(17*29)/29, back%(17*29)%29) +} + +//money 返回全部换算成纳特之后的总钱数 +func money(str string) int { + var intSlice []int + for _, v := range strings.Split(str, ".") { + tmp, err := strconv.Atoi(v) + if err == nil { + intSlice = append(intSlice, tmp) + } + } + sum := intSlice[0]*17*29 + intSlice[1]*29 + intSlice[2] + return sum +} diff --git "a/BasicLevel_Golang/1038. \347\273\237\350\256\241\345\220\214\346\210\220\347\273\251\345\255\246\347\224\237(20).go" "b/BasicLevel_Golang/1038. \347\273\237\350\256\241\345\220\214\346\210\220\347\273\251\345\255\246\347\224\237(20).go" new file mode 100644 index 0000000..8d034c3 --- /dev/null +++ "b/BasicLevel_Golang/1038. \347\273\237\350\256\241\345\220\214\346\210\220\347\273\251\345\255\246\347\224\237(20).go" @@ -0,0 +1,40 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + var ( + N int + score = []string{} + search = []string{} + n [101]int + ) + fmt.Scanln(&N) + inputReader := bufio.NewReader(os.Stdin) + if input1, err1 := inputReader.ReadString('\n'); err1 == nil { + score = strings.Fields(input1) + } + if input2, err2 := inputReader.ReadString('\n'); err2 == nil { + search = strings.Fields(input2) + } + for _, v := range score { + if cur, err := strconv.Atoi(v); err == nil { + n[cur]++ + } + } + w1 := bufio.NewWriter(os.Stdout) + for i := 1; i < len(search); i++ { + if i != 1 { + w1.WriteString(" ") + } + cur, _ := strconv.Atoi(search[i]) + w1.WriteString(fmt.Sprintf("%d", n[cur])) + } + w1.Flush() +} diff --git "a/BasicLevel_Golang/1039. \345\210\260\345\272\225\344\271\260\344\270\215\344\271\260\357\274\21020\357\274\211.go" "b/BasicLevel_Golang/1039. \345\210\260\345\272\225\344\271\260\344\270\215\344\271\260\357\274\21020\357\274\211.go" new file mode 100644 index 0000000..93c47ac --- /dev/null +++ "b/BasicLevel_Golang/1039. \345\210\260\345\272\225\344\271\260\344\270\215\344\271\260\357\274\21020\357\274\211.go" @@ -0,0 +1,28 @@ +package main + +import "fmt" + +func main() { + var ( + sell, buy string + num [256]int + result int + ) + fmt.Scanln(&sell) + fmt.Scanln(&buy) + for _, v := range sell { + num[v]++ + } + for _, v := range buy { + if num[v] > 0 { + num[v]-- + } else { + result++ + } + } + if result != 0 { + fmt.Println("No", result) + } else { + fmt.Println("Yes", len(sell)-len(buy)) + } +} diff --git "a/BasicLevel_Golang/1040. \346\234\211\345\207\240\344\270\252PAT(25).go" "b/BasicLevel_Golang/1040. \346\234\211\345\207\240\344\270\252PAT(25).go" new file mode 100644 index 0000000..034eaf9 --- /dev/null +++ "b/BasicLevel_Golang/1040. \346\234\211\345\207\240\344\270\252PAT(25).go" @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + var ( + str string + countt, countp, count int + ) + fmt.Scanln(&str) + countt = strings.Count(str, "T") + for _, v := range str { + if v == 'P' { + countp++ + } + if v == 'T' { + countt-- + } + if v == 'A' { + count = count + countp*countt + } + } + fmt.Println(count % 1000000007) +} diff --git "a/BasicLevel_Golang/1041. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267(15).go" "b/BasicLevel_Golang/1041. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267(15).go" new file mode 100644 index 0000000..3c8d38e --- /dev/null +++ "b/BasicLevel_Golang/1041. \350\200\203\350\257\225\345\272\247\344\275\215\345\217\267(15).go" @@ -0,0 +1,35 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +//Student 考生信息 +type Student struct { + id string + real int +} + +func main() { + var ( + student = map[string]Student{} + N, M int + ) + fmt.Scanln(&N) + for i := 0; i < N; i++ { + var tmpid, tmptest string + var tmpreal int + fmt.Scanln(&tmpid, &tmptest, &tmpreal) + student[tmptest] = Student{tmpid, tmpreal} + } + fmt.Scanln(&M) + inputReader := bufio.NewReader(os.Stdin) + t, _ := inputReader.ReadString('\n') + result := strings.Fields(t) + for _, v := range result { + fmt.Println(student[v].id, student[v].real) + } +} diff --git "a/BasicLevel_Golang/1042. \345\255\227\347\254\246\347\273\237\350\256\241(20).go" "b/BasicLevel_Golang/1042. \345\255\227\347\254\246\347\273\237\350\256\241(20).go" new file mode 100644 index 0000000..eb75d3a --- /dev/null +++ "b/BasicLevel_Golang/1042. \345\255\227\347\254\246\347\273\237\350\256\241(20).go" @@ -0,0 +1,27 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func main() { + var ( + str string + count int + letter rune + ) + inputReader := bufio.NewReader(os.Stdin) + str, _ = inputReader.ReadString('\n') + Lower := strings.ToLower(str) + count, letter = strings.Count(Lower, "a"), 'a' + for i := 'b'; i <= 'z'; i++ { + tmp := strings.Count(Lower, string(i)) + if tmp > count { + letter, count = i, tmp + } + } + fmt.Printf("%c %d", letter, count) +} diff --git "a/BasicLevel_Golang/1043. \350\276\223\345\207\272PATest(20).go" "b/BasicLevel_Golang/1043. \350\276\223\345\207\272PATest(20).go" new file mode 100644 index 0000000..d2b7e21 --- /dev/null +++ "b/BasicLevel_Golang/1043. \350\276\223\345\207\272PATest(20).go" @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + var ( + str string + count int + ) + fmt.Scanln(&str) + //str = "redlesPayBestPATTopTeePHPereatitAPPT" + P, A, T := strings.Count(str, "P"), strings.Count(str, "A"), strings.Count(str, "T") + e, s, t := strings.Count(str, "e"), strings.Count(str, "s"), strings.Count(str, "t") + count = P + A + T + e + s + t + for i := 0; i < count; i++ { + if P > 0 { + fmt.Printf("P") + P-- + } + if A > 0 { + fmt.Printf("A") + A-- + } + if T > 0 { + fmt.Printf("T") + T-- + } + if e > 0 { + fmt.Printf("e") + e-- + } + if s > 0 { + fmt.Printf("s") + s-- + } + if t > 0 { + fmt.Printf("t") + t-- + } + } +} diff --git "a/BasicLevel_Golang/1044. \347\201\253\346\230\237\346\225\260\345\255\227(20).go" "b/BasicLevel_Golang/1044. \347\201\253\346\230\237\346\225\260\345\255\227(20).go" new file mode 100644 index 0000000..f775426 --- /dev/null +++ "b/BasicLevel_Golang/1044. \347\201\253\346\230\237\346\225\260\345\255\227(20).go" @@ -0,0 +1,57 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + var ( + N int + a = [13]string{"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"} + b = [13]string{"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"} + ) + fmt.Scanln(&N) + inputReader := bufio.NewReader(os.Stdin) + for i := 0; i < N; i++ { + t, err := inputReader.ReadString('\n') + if err != nil { + fmt.Println("Read error") + } + t = strings.TrimSpace(t) + if t[0] >= '0' && t[0] <= '9' { + tmp, err1 := strconv.Atoi(t) + if err1 != nil { + fmt.Println("conert error") + } + if tmp/13 != 0 { + fmt.Printf("%s", b[tmp/13]) + } + if tmp/13 != 0 && tmp%13 != 0 { + fmt.Printf(" ") + } + if tmp%13 != 0 || tmp == 0 { + fmt.Printf("%s", a[tmp%13]) + } + fmt.Printf("\n") + } else { + var t1, t2 int + num := strings.Fields(t) + if len(num) == 1 { + num = append(num, "") + } + for j := 1; j < 13; j++ { + if num[0] == a[j] || num[1] == a[j] { + t2 = j + } + if num[0] == b[j] { + t1 = j + } + } + fmt.Printf("%d\n", t1*13+t2) + } + } +} diff --git "a/BasicLevel_Golang/1045. \345\277\253\351\200\237\346\216\222\345\272\217(25).go" "b/BasicLevel_Golang/1045. \345\277\253\351\200\237\346\216\222\345\272\217(25).go" new file mode 100644 index 0000000..54211a4 --- /dev/null +++ "b/BasicLevel_Golang/1045. \345\277\253\351\200\237\346\216\222\345\272\217(25).go" @@ -0,0 +1,51 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "sort" + "strconv" + "strings" +) + +func main() { + var ( + N int + a, b, c []int + max int + ) + fmt.Scanln(&N) + inputReader := bufio.NewReader(os.Stdin) + t, err := inputReader.ReadString('\n') + if err != nil { + fmt.Println("can't read numbers!") + } + str := strings.Fields(t) + for _, v := range str { + num, err := strconv.Atoi(v) + if err != nil { + fmt.Println("convert to int error!") + } + a, b = append(a, num), append(b, num) + } + sort.Ints(b) + for k, v := range b { + if v == a[k] && a[k] > max { + c = append(c, v) + } + if a[k] > max { + max = a[k] + } + } + fmt.Println(len(c)) + w1 := bufio.NewWriter(os.Stdout) + for k, v := range c { + if k != 0 { + w1.WriteString(fmt.Sprintf(" ")) + } + w1.WriteString(fmt.Sprintf("%d", v)) + } + w1.Flush() + fmt.Printf("\n") +} diff --git "a/BasicLevel_Golang/1046. \345\210\222\346\213\263(15).go" "b/BasicLevel_Golang/1046. \345\210\222\346\213\263(15).go" new file mode 100644 index 0000000..edb19d7 --- /dev/null +++ "b/BasicLevel_Golang/1046. \345\210\222\346\213\263(15).go" @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" +) + +func main() { + var ( + N int + win [2]int + ) + fmt.Scanln(&N) + for i := 0; i < N; i++ { + var jiahan, jiahua, yihan, yihua int + fmt.Scanln(&jiahan, &jiahua, &yihan, &yihua) + count := jiahan + yihan + if jiahua == count && yihua != count { + win[1]++ + } + if yihua == count && jiahua != count { + win[0]++ + } + } + fmt.Println(win[0], win[1]) + +} diff --git "a/BasicLevel_Golang/1047. \347\274\226\347\250\213\345\233\242\344\275\223\350\265\233(20).go" "b/BasicLevel_Golang/1047. \347\274\226\347\250\213\345\233\242\344\275\223\350\265\233(20).go" new file mode 100644 index 0000000..4b8d3ac --- /dev/null +++ "b/BasicLevel_Golang/1047. \347\274\226\347\250\213\345\233\242\344\275\223\350\265\233(20).go" @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + "strconv" + "strings" +) + +func main() { + var ( + N int + group [1001]int + winID, winScore int + ) + fmt.Scanln(&N) + for i := 0; i < N; i++ { + var ( + id string + score int + ) + fmt.Scanln(&id, &score) + groupIDStr := strings.Split(id, "-") + groupID, err := strconv.Atoi(groupIDStr[0]) + if err != nil { + fmt.Println("convert string to int error!") + } + group[groupID] += score + } + for k, v := range group { + if v > winScore { + winID, winScore = k, v + } + } + fmt.Println(winID, winScore) + +} diff --git "a/BasicLevel_Golang/1048. \346\225\260\345\255\227\345\212\240\345\257\206(20).go" "b/BasicLevel_Golang/1048. \346\225\260\345\255\227\345\212\240\345\257\206(20).go" new file mode 100644 index 0000000..1f8b8ec --- /dev/null +++ "b/BasicLevel_Golang/1048. \346\225\260\345\255\227\345\212\240\345\257\206(20).go" @@ -0,0 +1,44 @@ +package main + +import "fmt" + +func main() { + var ( + A, B string + C []string + ) + fmt.Scanln(&A, &B) + numA, numB := reverseString(A), reverseString(B) + if len(numA) > len(numB) { + for len(numA)-len(numB) > 0 { + numB = append(numB, rune('0')) + } + } else { + for len(numB)-len(numA) > 0 { + numA = append(numA, rune('0')) + } + } + str := "0123456789JQK" + for k, v := range numA { + if k%2 == 0 { + C = append(C, string(str[(v-'0'+numB[k]-'0')%13])) + } else { + temp := numB[k] - v + if temp < 0 { + temp = temp + 10 + } + C = append(C, string(str[temp])) + } + } + for i := len(C) - 1; i >= 0; i-- { + fmt.Printf("%s", C[i]) + } +} + +func reverseString(s string) []rune { + runes := []rune(s) + for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 { + runes[from], runes[to] = runes[to], runes[from] + } + return runes +} diff --git "a/BasicLevel_Golang/1049. \346\225\260\345\210\227\347\232\204\347\211\207\346\256\265\345\222\214(20).go" "b/BasicLevel_Golang/1049. \346\225\260\345\210\227\347\232\204\347\211\207\346\256\265\345\222\214(20).go" new file mode 100644 index 0000000..b48e9c8 --- /dev/null +++ "b/BasicLevel_Golang/1049. \346\225\260\345\210\227\347\232\204\347\211\207\346\256\265\345\222\214(20).go" @@ -0,0 +1,28 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "strings" +) + +func main() { + var ( + N int + sum float64 + ) + fmt.Scanln(&N) + inputReader := bufio.NewReader(os.Stdin) + series, err := inputReader.ReadString('\n') + if err != nil { + fmt.Printf("read string error") + } + num := strings.Fields(series) + for i := 1; i <= N; i++ { + t, _ := strconv.ParseFloat(num[i-1], 64) + sum += t * float64(i*(N-i+1)) + } + fmt.Printf("%.2f", sum) +} diff --git "a/BasicLevel_Golang/1050. \350\236\272\346\227\213\347\237\251\351\230\265(25).go" "b/BasicLevel_Golang/1050. \350\236\272\346\227\213\347\237\251\351\230\265(25).go" new file mode 100644 index 0000000..8db37d8 --- /dev/null +++ "b/BasicLevel_Golang/1050. \350\236\272\346\227\213\347\237\251\351\230\265(25).go" @@ -0,0 +1,68 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "sort" + "strconv" + "strings" +) + +func main() { + var ( + N int + series []int + result [][]int + ) + fmt.Scanln(&N) + r := bufio.NewReader(os.Stdin) + input, err1 := r.ReadString('\n') + if err1 != nil { + fmt.Println("Read numbers error") + } + s := strings.Fields(strings.TrimRight(input, "\n")) + for _, v := range s { + num, err2 := strconv.Atoi(v) + if err2 != nil { + fmt.Println("convert string to int error", v) + } + series = append(series, num) + } + sort.Sort(sort.Reverse(sort.IntSlice(series))) + m, n := N, 1 + for ; n <= N/n; n++ { + if N%n == 0 && N/n-n < m { + m = N / n + } + } + n = N / m + w := bufio.NewWriter(os.Stdout) + for i := 0; i < m; i++ { + result = append(result, make([]int, n)) + } + x, y, d := 0, 0, 0 + dx := []int{0, 1, 0, -1} + dy := []int{1, 0, -1, 0} + for t := 0; t < N; t++ { + result[x][y] = series[t] + nx, ny := x+dx[d], y+dy[d] + if nx < 0 || nx >= m || ny < 0 || ny >= n || result[nx][ny] != 0 { + d = (d + 1) % 4 + nx = x + dx[d] + ny = y + dy[d] + } + x = nx + y = ny + } + for i := 0; i < m; i++ { + for j := 0; j < n; j++ { + w.WriteString(fmt.Sprintf("%d", result[i][j])) + if j != n-1 { + w.WriteString(fmt.Sprintf(" ")) + } + } + w.WriteString(fmt.Sprintf("\n")) + } + w.Flush() +}