상세 컨텐츠

본문 제목

백준# 9933 - 민균이의 비밀번호

C#/알고리즘

by McRobbin 2020. 5. 15. 16:12

본문

https://www.acmicpc.net/problem/9933

 

9933번: 민균이의 비밀번호

문제 창영이는 민균이의 컴퓨터를 해킹해 텍스트 파일 하나를 자신의 메일로 전송했다. 파일에는 단어가 한 줄에 하나씩 적혀있었고, 이 중 하나는 민균이가 온라인 저지에서 사용하는 비밀번��

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _9933
{
    class Program
    {
        public static string Reverse(string input)
        {
            string rtnString = "";
            for (int i = input.Length - 1; i >= 0; i--)
                rtnString += input.Substring(i, 1);
 
            return rtnString;
        }
 
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            var wordList = new List<string>();
 
            for(int i = 0; i < count; i++)
                wordList.Add(Console.ReadLine());
 
            foreach (string word in wordList)
            {
                if(wordList.Find(x => x == Program.Reverse(word)) != null)
                {
                    Console.Write(word.Length + " " + word[word.Length / 2]);
                    break;
                }
            }
        }
    }
}
 
 
cs

모든 스트링에 대해 Reverse해보고 비교해보면 되겠습니다.

관련글 더보기