답안 #257935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257935 2020-08-05T05:19:26 Z MrRobot_28 Datum (COCI20_datum) C++17
50 / 50
34 ms 1528 KB
#include<bits/stdc++.h>
using namespace std;
bool cmp(vector <int> a, vector <int> b)
{
	if(a[2] != b[2])
	{
		return a[2] < b[2];
	}
	else if(a[1] != b[1])
	{
		return a[1] < b[1];
	}
	else
	{
		return a[0] < b[0];
	}
}
signed main() {
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
//	cout.tie(NULL);
	int n;
	cin >> n;
	vector <vector <int> > a(n, vector <int> (4));
	for(int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		a[i][0] = (s[0] - '0') * 10 + s[1] - '0';
		a[i][1] = (s[3] - '0') * 10 + s[4] - '0';
		a[i][2] = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');
		a[i][3] = i;
	}
	sort(a.begin(), a.end(), cmp);
	vector <vector <int> > mass;
	for(int c = 0; c < 10000; c++)
	{
		int a = (c % 10) * 10 + (c / 10) % 10;
		int b = ((c / 100) % 10) * 10 + c / 1000;
		if(b > 0 && b <= 12){
			if(b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)
			{
				if(a > 0 && a < 32)
				{
					vector <int> pu;
					pu.push_back(a);
					pu.push_back(b);
					pu.push_back(c);
					mass.push_back(pu);
				}
			}
			else if(b == 2)
			{
				if(c % 400 == 0 || c % 4 == 0 && c % 100 != 0)
				{
					if(a > 0 && a < 30)
					{vector <int> pu;
					pu.push_back(a);
					pu.push_back(b);
					pu.push_back(c);
					mass.push_back(pu);
					}
				}
				else
				{
					if(a > 0 && a < 29)
					{vector <int> pu;
					pu.push_back(a);
					pu.push_back(b);
					pu.push_back(c);
					mass.push_back(pu);
					}
				}
			}
			else if(a > 0 && a < 31)
			{vector <int> pu;
					pu.push_back(a);
					pu.push_back(b);
					pu.push_back(c);
					mass.push_back(pu);
			}
		}
	}
	vector <vector <int> > ans(n, vector <int> (3));
	int it = 0;
	for(int i = 0; i < n; i++)
	{
		while(a[i][2] > mass[it][2] || (a[i][2] == mass[it][2] && (a[i][1] > mass[it][1] || (a[i][1] == mass[it][1] && a[i][0] >= mass[it][0]))))
		{
			it++;
		}
		ans[a[i][3]] = mass[it];	
	}
	for(int i = 0; i < n; i++)
	{
		cout << ans[i][0] / 10 << ans[i][0] % 10 << ".";
		cout << ans[i][1] / 10 << ans[i][1] % 10 << ".";
		cout << ans[i][2] / 1000 << ans[i][2] / 100 % 10 << ans[i][2] / 10 % 10 << ans[i][2] % 10 << ".\n";
	}
  	return 0;
}

Compilation message

datum.cpp: In function 'int main()':
datum.cpp:54:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     if(c % 400 == 0 || c % 4 == 0 && c % 100 != 0)
                        ~~~~~~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 34 ms 1528 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 26 ms 1528 KB Output is correct