A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Duplicate Character Counter in V page! Here, you'll find the source code for this program as well as a description of how the program works.
import os
fn show_error() {
println('Usage: please provide a string')
}
fn main() {
args := os.args[1..] // skip program name
if args.len == 0 {
show_error()
return
}
input_str := args[0]
if input_str.len == 0 {
show_error()
return
}
mut counts := map[rune]int{}
for c in input_str.runes() {
counts[c]++
}
mut found := false
for c in input_str.runes() {
if counts[c] > 1 {
println('${c.str()}: ${counts[c]}')
counts[c] = 0 // prevent duplicate printing
found = true
}
}
if !found {
println('No duplicate characters')
}
}
Duplicate Character Counter in V was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.