Taene's
[백준] 브론즈3-팰린드롬인지 확인하기 C++ 10988번 본문
// 일반 풀이
#include <iostream>
using namespace std;
string pel;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> pel;
int start = 0;
int end = pel.length() - 1;
while (start <= end)
{
if (pel[start] != pel[end])
{
cout << 0;
return 0;
}
start++;
end--;
}
cout << 1;
return 0;
}
// algorithm - reverse() 사용
#include <iostream>
#include <algorithm>
using namespace std;
string pel;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> pel;
string tmp = pel;
reverse(pel.begin(), pel.end());
if (tmp == pel)
cout << 1;
else
cout << 0;
return 0;
}'백준 > 브론즈' 카테고리의 다른 글
| [백준] 브론즈1-ROT13 C++ 11655번 (0) | 2025.02.22 |
|---|---|
| [백준] 브론즈2-트럭 주차 C++ 2979번 (0) | 2025.02.21 |
| [백준] 브론즈4-알파벳 개수 C++ 10808번 (0) | 2025.02.21 |
| [백준] 브론즈1-일곱 난쟁이 C++ 2309번 (0) | 2025.02.21 |
| [백준] 브론즈1-평균 C++ 1546번 (0) | 2024.02.26 |