SMALL
https://www.acmicpc.net/problem/10988
10988번: 팰린드롬인지 확인하기
첫째 줄에 단어가 주어진다. 단어의 길이는 1보다 크거나 같고, 100보다 작거나 같으며, 알파벳 소문자로만 이루어져 있다.
www.acmicpc.net
- 문제
- 문제풀이
문자를 쪼개서 거꾸로 비교해나간다.
- 코드 1
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
bool check = true;
for (int f = 0, l = input.Length - 1 - f; f < l; f++, l--)
{
if (input[f] != input[l])
{
check = false;
}
else
{
continue;
}
}
if (check)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}
}
}
- 코드2
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
char[] inputarr = input.ToCharArray();
string reverse="";
for(int i = inputarr.Length-1; i >=0; i--)
{
reverse += inputarr[i];
}
if (input == reverse)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
}
}
}
- 후기
C#은 자체 함수가 많아서 참 좋다
LIST
'백준 > C#' 카테고리의 다른 글
[C#]백준 1157번: 단어공부 (0) | 2023.07.19 |
---|---|
[C#]백준 25206: 너의 평점은 (0) | 2023.07.19 |
[C#]백준 23292번: 코딩 바이오리듬 (0) | 2023.07.19 |
[C#]백준 15652번: N과 M(4) (0) | 2023.07.19 |
[C#]백준 15651번: N과 M(3) (0) | 2023.07.19 |