본문 바로가기

프로그래밍/10주완성코딩테스트

10988_팰린드롬인지 확인하기

-문제

-접근

arr[i] 와 arr[len-i]를 비교한다.

-내풀이

#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(void){
	int i,len;
	bool flag=true;
	string arr;
	cin >> arr;
	len=arr.size();
	for(i=0;i<len/2;i++){
		if(arr[i] != arr[len-i-1]){
			flag=false;
			break;
		}
	}
	if(flag)
		cout << "1";
	else 
		cout << "0";
}

 

-해설풀이

기존 문자열과 반전시킨 문자열을 비교한다.

#include<bits/stdc++.h>
using namespace std;
string s,temp;
int main(void){
	cin >> s;
	temp=s;
	reverse(temp.begin(),temp.end());
	if(temp==s) cout << "1" <<endl;
	else cout << "0" <<endl;	
}

-메모

reverse함수 반환값 없음

'프로그래밍 > 10주완성코딩테스트' 카테고리의 다른 글

2583 영역 구하기  (0) 2022.06.20
2583_영역 구하기  (0) 2022.06.13
2979_트럭 주차  (0) 2022.05.19
10808_알파벳 개수  (0) 2022.05.19
2309_일곱난쟁이  (0) 2022.05.19