We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d7be67c commit 6041a2fCopy full SHA for 6041a2f
archive/v/v/duplicate-character-counter.v
@@ -0,0 +1,36 @@
1
+import os
2
+
3
+fn show_error() {
4
+ println('Usage: please provide a string')
5
+}
6
7
+fn main() {
8
+ args := os.args[1..] // skip program name
9
+ if args.len == 0 {
10
+ show_error()
11
+ return
12
+ }
13
+ input_str := args[0]
14
+ if input_str.len == 0 {
15
16
17
18
19
+ mut counts := map[rune]int{}
20
+ for c in input_str.runes() {
21
+ counts[c]++
22
23
24
+ mut found := false
25
26
+ if counts[c] > 1 {
27
+ println('${c.str()}: ${counts[c]}')
28
+ counts[c] = 0 // prevent duplicate printing
29
+ found = true
30
31
32
33
+ if !found {
34
+ println('No duplicate characters')
35
36
0 commit comments