More actions
imported>Unknown No edit summary |
(Repair batch-0001 pages from live compare) |
||
| Line 13: | Line 13: | ||
for(int i = 0; i < len/2; i++) | for(int i = 0; i < len/2; i++) | ||
{ | { | ||
if(string | if(string[i] == string[len-i-1]) | ||
isPal = true; | isPal = true; | ||
else { | else { | ||
| Line 26: | Line 26: | ||
int main() | int main() | ||
{ | { | ||
char str | char str[20]; | ||
int len; | int len; | ||
while(cin >> str) | while(cin >> str) | ||
| Line 48: | Line 48: | ||
{ | { | ||
bool isPal = false; | bool isPal = false; | ||
if(string | if(string[0] >= 'a' && string[0] <= 'z' || string[0] >= 'A' && string[0] <= 'Z') | ||
{ | { | ||
for(int i = 0; i < len/2; i++) | for(int i = 0; i < len/2; i++) | ||
{ | { | ||
if(string | if(string[i] == string[len-i-1]) | ||
isPal = true; | isPal = true; | ||
else { | else { | ||
| Line 64: | Line 64: | ||
for(int j = 0; j < 2; j++) | for(int j = 0; j < 2; j++) | ||
{ | { | ||
if(string | if(string[i+j] == string[len-i-2+j]) | ||
isPal = true; | isPal = true; | ||
else { | else { | ||
| Line 78: | Line 78: | ||
int main() | int main() | ||
{ | { | ||
char str | char str[20]; | ||
int len; | int len; | ||
while(cin >> str) | while(cin >> str) | ||
Latest revision as of 23:56, 26 March 2026
이야기
오늘 짰던 AOI문제와 비슷해서 쉬웠다. 한글인지 아닌지 판단해서, 구분하는 것도 만들어 볼 생각이다.,
코드
#include <iostream>
using namespace std;
bool isPalindrome(char *string, int len)
{
bool isPal = false;
for(int i = 0; i < len/2; i++)
{
if(string[i] == string[len-i-1])
isPal = true;
else {
isPal = false;
break;
}
}
return isPal;
}
int main()
{
char str[20];
int len;
while(cin >> str)
{
len = strlen(str);
if(isPalindrome(str, len))
cout << "->true" << endl;
else
cout << "->false" << endl;
}
return 0;
}
버젼 2. 영어 + 한글 + 버그수정
#include <iostream>
using namespace std;
bool isPalindrome(char *string, int len)
{
bool isPal = false;
if(string[0] >= 'a' && string[0] <= 'z' || string[0] >= 'A' && string[0] <= 'Z')
{
for(int i = 0; i < len/2; i++)
{
if(string[i] == string[len-i-1])
isPal = true;
else {
isPal = false;
break;
}
}
} else {
for(int i = 0; i < (len-1)/2; i += 2)
{
for(int j = 0; j < 2; j++)
{
if(string[i+j] == string[len-i-2+j])
isPal = true;
else {
isPal = false;
break;
}
}
}
}
return isPal;
}
int main()
{
char str[20];
int len;
while(cin >> str)
{
len = strlen(str);
if(len == 1)
cout << "->true" << endl;
else if(isPalindrome(str, len))
cout << "->true" << endl;
else
cout << "->false" << endl;
}
return 0;
}