반응형

문제

https://www.acmicpc.net/problem/9996

 

11655번: ROT13

첫째 줄에 알파벳 대문자, 소문자, 공백, 숫자로만 이루어진 문자열 S가 주어진다. S의 길이는 100을 넘지 않는다.

www.acmicpc.net

풀이 과정

1. * 앞 뒤와 파일 이름을 비교한다.

2. 반례를 생각하여 적용한다.

 

문제점

처음 반례 부분을 작성하지 않아 계속하여 채점에서 틀렸다고 나왔습니다.

그래서 찾다보니, 이럴 경우 반례가 나오게 되어 틀렸던거였습니다.. ㅠㅠ

// ** 예시 **
// Input
1
ad*ad
ad

// output
틀림

즉, 이렇게 될 경우

코드 ( C++ )

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N = 0;
	string str = "";

	cin >> N;
	cin >> str;
	int pos = str.find("*");
	string pre = str.substr(0, pos);
	string suf = str.substr(pos + 1);

	for (int i = 0; i < N; ++i)
	{
		string temp;
		cin >> temp;
		if (pre.size() + suf.size() > temp.size())
		{
			cout << "NE" << endl;
		}
		else
		{
			if (pre == temp.substr(0, pre.size()) && suf == temp.substr(temp.size() - suf.size()))
			{
				cout << "DA" << endl;
			}
			else
			{
				cout << "NE" << endl;
			}
		}
	}
	return 0;
}
반응형

'Etc > Algorithm' 카테고리의 다른 글

[BOJ] 2559 수열  (0) 2022.07.17
[BOJ]11655번 ROT13  (0) 2022.07.14
[BOJ]2979번 트럭 주차  (0) 2022.07.13
[BOJ]10808-알파벳 개수  (0) 2022.07.12
[BOJ]2309-일곱 난쟁이  (0) 2022.07.11

+ Recent posts