코딩 테스트/BOJ
C# 10808 알파벳 개수
s0002
2023. 1. 19. 20:04
알파벳을 key, 알파벳 개수를 value로 하는 딕셔너리 생성
단어를 입력받고
입력받은 단어에 나오는 알파벳을 key로 하는 value의 값을 1씩 증가
using System;
using System.Collections.Generic;
namespace _10808
{
class Program
{
static void Main(string[] args)
{
Dictionary<char, int> dic = new Dictionary<char, int>();
char key = 'a';
for (int i = 0; i <26; i++)
{
dic.Add(key, 0);
key++;
}
string word = Console.ReadLine();
for (int i = 0; i < word.Length; i++)
dic[word[i]]++;
foreach(KeyValuePair<char,int> pair in dic)
Console.Write("{0} ", pair.Value);
}
}
}
https://www.acmicpc.net/problem/10808
10808번: 알파벳 개수
단어에 포함되어 있는 a의 개수, b의 개수, …, z의 개수를 공백으로 구분해서 출력한다.
www.acmicpc.net