U E D R , A S I H C RSS

Automated Judge Script/문보창

소감

2005/02/19 Accepted 0:00.006 64
단순한 문자열 비교문제라는 생각이 들었다. Presentation Error와 Accepted 를 어떻게 하면 쉽게 구별할 수 있을지를 고민하다 입력받을때부터 숫자를 따로 입력받는 배열을 만들어 주는 방법을 이용하였다.

코드

~cpp 
// no10188 - Automated Judge Script
#include <iostream>
#include <cstring>
using namespace std;

const int MAX = 100;

bool setString(char * s, char * sDigit);

int main()
{
	char answer[MAX*MAX];			// 정답
	char answerDigit[MAX];
	char reply[MAX*MAX];			// 사용자 출력
	char replyDigit[MAX];
	int count = 1;
	while (true)
	{
		if (!setString(answer, answerDigit) || !setString(reply, replyDigit))
			break;
		cout << "Run #" << count++;
		if (strcmp(answerDigit, replyDigit) != 0)
			cout << ": Wrong Answer\n";
		else if (strcmp(answer, reply) == 0)
			cout << ": Accepted\n";
		else
			cout << ": Presentation Error\n";
	}
	return 0;
}

bool setString(char * s, char * sDigit)
{
	int n;
	cin >> n;
	if (n == 0)
		return false;
	cin.get();
	int nDigit, nChar, nReturn;
	nDigit = nChar = nReturn = 0;
	char c;
	while (true)
	{
		c = cin.get();
		if (c == '\n')
			nReturn++;
		if (nReturn == n)
			break;
		if (c >= '0' && c <= '9')
			sDigit[nDigit++] = c; 
		s[nChar++] = c;
	}
	sDigit[nDigit] = '\0';
	s[nChar] = '\0';
	return true;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:33
Processing time 0.0087 sec