끄적끄적 코딩
article thumbnail

문자열 문제입니다.

문자를 뒤집었을 때도 같은 문자일 경우 1을
아닐 경우 0을 출력합니다.

문자의 처음 = start
문자의 끝 = end
라고 했을 때

if(s[start +i] != s[end - i]) cout << "-1" << endl;
다음과 같이 나타낼 수 있습니다.

 

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(int argc, char* argv[])
{
	string s;

	cin >> s;

	for (int i = 0; i < s.length() / 2; ++i) {
		if (s[i] != s[s.length() - i - 1]) {
			cout << "0" << endl;
			return 0;
		}
	}

	cout << "1" << endl;
	return 0;
}

'알고리즘' 카테고리의 다른 글

[C++] 백준 2864번 5와 6의 차이  (0) 2019.09.12
[C++] 백준 11656번 접미사 배열  (0) 2019.09.12
[C++] 백준 15353번 큰 수 A+B (2)  (0) 2019.09.12
[C++] 백준 10757번 큰 수 A+B  (0) 2019.09.12
[C++] 백준 15740번 A+B - 9  (0) 2019.09.12

검색 태그