본문 바로가기

Study/Baekjoon & SW Expert Academy

[SW Expert Academy : 1986번 지그재그 숫자, 1989번 초심자의 회문 검사]

오늘은 SW Expert Academy의 문제 2개를 준비해습니다!

 

첫번째 문제는 정답률 84.77의 1986번 지그재그 숫자이고,

두번째 문제는 정답률 79.86의 1989번 초심자의 회문 문제입니다.

 

SW Expert Academy 홈페이지 : https://swexpertacademy.com/main/main.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

만약 문제가 잘 풀리지 않는다면 다음 코드를 참고해서 다시 도전해보세요!

코드는 C++을 기반으로 작성되었습니다.

 

 

 

 

1986번 지그재그 숫자

 

#include <iostream>
using namespace std;


int main() {


	int t;	//test case
	int cnt = 1;
	int n;
	int result;
	
	cin >> t;

	while (t--) {

		cin >> n;

		if (n % 2 == 1) {

			result = n / 2 + 1;

		}
		else {
			result = (n / 2) * (-1);
		}

		cout << "#" << cnt++ << " " << result << "\n";

	}

	   	  
	return 0;
}

 

 

 

 

1989번 초심자의 회문 검사

 

#include <iostream>
#include <string>
using namespace std;


int main() {

	int test;	//test case
	int cnt = 1;
	string palindrome;
	int check = 1;


	cin >> test;

	while (test--) {

		cin >> palindrome;

			if (palindrome.length() % 2 == 0) {

				for (int i = 0; i < palindrome.length() / 2; i++) {

					if (palindrome[i] == palindrome[palindrome.length() - 1 - i])
						continue;
					else {
						check = 0;
					}
				}

			}
			else {

				for (int i = 0; i < (palindrome.length() / 2) + 1; i++) {

					if (palindrome[i] == palindrome[palindrome.length() - 1 - i])
						continue;
					else {
						check = 0;
					}


				}

			}

			cout << "#" << cnt++ << " " << check << "\n";
			check = 1;

	}

	return 0;
}

 

 

오늘은 정답률이 높은 문제 2가지를 풀어봤습니다.

다음에는 좀 더 어려운 문제를 풀어보도록 해야겠네요~