답안 #238547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238547 2020-06-11T18:29:51 Z Borbi Datum (COCI20_datum) C++14
40 / 50
336 ms 504 KB
#include <bits/stdc++.h>

using namespace std;

char str[20];
char new_s[20];

bool check()
{
	int mon = new_s[3] - '0';
	mon *= 10; mon += new_s[4] - '0';
	int day = new_s[0] - '0'; day *= 10; day += new_s[1] - '0';
	
	int year = 0;
	for(int i = 6; i <= 9; i++)
	{
		year *= 10;
		year += new_s[i] - '0';
	}

	int mon1 = str[3] - '0';
	mon1 *= 10; mon1 += str[4] - '0';
	int day1 = str[0] - '0'; day1 *= 10; day1 += str[1] - '0';
	
	int year1 = 0;
	for(int i = 6; i <= 9; i++)
	{
		year1 *= 10;
		year1 += str[i] - '0';
	}

	if(year < year1) return false;
	else if(year > year1) return true;
	if(mon < mon1) return false;
	if(mon > mon1) return true;
	if(day < day1) return false;
	if(day > day1) return true;
	return false;

	/*bool fl = false;
	for(int i = 6; i <= 9; i++)
	{
		if(str[i] > new_s[i]) return false;
		if(str[i] != new_s[i]) fl = true;
	}
	if(fl) return true;
	for(int i = 3; i <= 4; i++)
	{
		if(str[i] > new_s[i]) return false;
	
		if(str[i] != new_s[i]) fl = true;
	}
	if(fl) return true;
	for(int i = 0; i <= 1; i++)
	{
		if(str[i] > new_s[i]) return false;
	
		if(str[i] != new_s[i]) fl = true;
	}
	return fl;*/
}

bool legal()
{
	int mon = new_s[3] - '0';
	mon *= 10; mon += new_s[4] - '0';
	int day = new_s[0] - '0'; day *= 10; day += new_s[1] - '0';
	
	if(mon > 12) return false;
	int year = 0;
	for(int i = 6; i <= 9; i++)
	{
		year *= 10;
		year += new_s[i] - '0';
	}
	if(mon == 0 || day == 0) return false;
	if((mon & 1) == 0)
	{
		if(mon == 2)
		{	
			if(year % 4 == 0)
			{
				if(day > 29) return false;
			}
			else if(day > 28) return false;
		}
		else if(day > 30) return false;
	}
	else if(day > 31) return false;

	return true;
}

void solve()
{
	cin >> str;
	new_s[2] = new_s[5] = new_s[10] = '.';
	for(char i = '0'; i <= '9'; i++)
	{
		for(char j = '0'; j <= '9'; j++)
		{
			for(char z = '0'; z <= '9'; z++)
			{
				for(char h = '0'; h <= '9'; h++)
				{
					new_s[9] = new_s[0] = h; new_s[1] = new_s[8] = z; new_s[3] = new_s[7] = j; new_s[4] = new_s[6] = i;
					if(legal() && check())
					{
						for(int i = 0; i <= 10; i++)
						{
							cout << new_s[i];
						}
						cout << "\n";
						return;
					}
				}
			}
		}
	}
}

int main()
{
	int k;
	
	cin >> k;
	while(k--)
	{
		solve();
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 328 ms 504 KB Output isn't correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Incorrect 336 ms 480 KB Output isn't correct