Skip to content

Commit 2407e17

Browse files
committed
AcWing 第 16 场周赛
1 parent a109d09 commit 2407e17

File tree

6 files changed

+203
-0
lines changed

6 files changed

+203
-0
lines changed

misc/acwing/weekly/16/a/a.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
"os"
8+
"strings"
9+
"unicode"
10+
)
11+
12+
// github.com/EndlessCheng/codeforces-go
13+
func run(_r io.Reader, _w io.Writer) {
14+
in := bufio.NewReader(_r)
15+
out := bufio.NewWriter(_w)
16+
defer out.Flush()
17+
18+
var T int
19+
var s string
20+
for Fscan(in, &T); T > 0; T-- {
21+
Fscan(in, &s)
22+
low := 0
23+
for _, b := range s {
24+
if unicode.IsLower(b) {
25+
low++
26+
}
27+
}
28+
if low*2 < len(s) {
29+
Fprintln(out, strings.ToUpper(s))
30+
} else {
31+
Fprintln(out, strings.ToLower(s))
32+
}
33+
}
34+
}
35+
36+
func main() { run(os.Stdin, os.Stdout) }

misc/acwing/weekly/16/a/a_test.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/acwing/weekly/16/b/b.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
"os"
8+
)
9+
10+
// github.com/EndlessCheng/codeforces-go
11+
func run(_r io.Reader, out io.Writer) {
12+
in := bufio.NewReader(_r)
13+
var n, v, cnt2, ans int
14+
Fscan(in, &n)
15+
if n < 3 {
16+
Fprint(out, 0)
17+
return
18+
}
19+
20+
sum := make([]int, n+1)
21+
for i := 0; i < n; i++ {
22+
Fscan(in, &v)
23+
sum[i+1] = sum[i] + v
24+
}
25+
if sum[n]%3 != 0 {
26+
Fprint(out, 0)
27+
return
28+
}
29+
30+
avg := sum[n] / 3
31+
for _, s := range sum[1:n] {
32+
if s == avg*2 {
33+
cnt2++
34+
}
35+
}
36+
37+
// 把等于 avg 的前缀和当成第一组,然后累加前缀和等于 avg*2 的前缀和的个数
38+
for _, s := range sum[1:n] {
39+
if s == avg*2 {
40+
cnt2--
41+
}
42+
if s == avg {
43+
ans += cnt2
44+
}
45+
}
46+
Fprint(out, ans)
47+
}
48+
49+
func main() { run(os.Stdin, os.Stdout) }

misc/acwing/weekly/16/b/b_test.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/acwing/weekly/16/c/c.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
. "fmt"
6+
"io"
7+
"os"
8+
)
9+
10+
// github.com/EndlessCheng/codeforces-go
11+
func run(_r io.Reader, out io.Writer) {
12+
in := bufio.NewReader(_r)
13+
var n int
14+
Fscan(in, &n)
15+
a := make([]int, n)
16+
for i := range a {
17+
Fscan(in, &a[i])
18+
}
19+
for i := 1; i < n-1; i++ {
20+
if a[i] < a[i+1] && a[i] < a[0] || a[i] > a[i+1] && a[i] > a[0] {
21+
Fprintln(out, 3)
22+
Fprintln(out, 1, i+1, i+2)
23+
return
24+
}
25+
}
26+
Fprintln(out, 0)
27+
}
28+
29+
func main() { run(os.Stdin, os.Stdout) }

misc/acwing/weekly/16/c/c_test.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)