알고리즘/백준 BOJ
[ BOJ/C# ] 10809 알파벳 찾기
왹져박사
2023. 9. 7. 22:05
https://www.acmicpc.net/problem/10809
10809번: 알파벳 찾기
각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출
www.acmicpc.net
알파벳의 아스키코드를 이용하였다.
using System;
using System.Text;
namespace B10809
{
class Program
{
static void Main()
{
StreamReader sr = new StreamReader(Console.OpenStandardInput());
StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
StringBuilder sb = new StringBuilder();
string s = sr.ReadLine();
int[] pos = new int[26];
//모든 알파벳
for(int i=0; i<26; i++)
{
pos[i] = -1;
if (i!=0) sb.Append(" ");
//주어진 단어의 알파벳
for(int j = 0; j < s.Length; j++)
{
//글자의 j번째 숫자와 i가 같으면
if (s[j] - 97 == i && pos[i] == -1)
{
pos[i] = j;
break;
}
}
sb.Append(pos[i]);
}
sw.WriteLine(sb.ToString());
sr.Close();
sw.Flush();
sw.Close();
}
}
}


실버4로 승급했다!!
당분간은 프로젝트에 더 집중해야겠다!