답안 #291707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
291707 2020-09-05T17:09:27 Z penguinhacker Datum (COCI20_datum) C++14
50 / 50
7 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int d[13]={-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector<ar<int, 3>> dates; //year, month, day

string filler(int x, int d) {
	int digs=0;
	while(x>0) ++digs, x/=10;
	return string(d-digs, '0');
}

string To_string(int x) {
	string res;
	while(x>0) res.push_back(x%10+'0'), x/=10;
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	for (int i=0; i<10000; ++i) {
		int month=i/100; month=month%10*10+month/10;
		int day=i%100; day=day%10*10+day/10;
		if (month<1||month>12) continue;
		int bound=d[month];
		if (month==2&&i%4==0) ++bound;
		if (day==0||day>bound) continue;
		dates.push_back({i, month, day});
		//cout << i << "\n";
	}
	int n;
	cin >> n;
	for (int i=0; i<n; ++i) {
		string s; cin >> s;
		int day=atoi(s.substr(0, 2).c_str());
		int month=atoi(s.substr(3, 2).c_str());
		int year=atoi(s.substr(6, 4).c_str());
		int pos=upper_bound(dates.begin(), dates.end(), ar<int, 3>{year, month, day})-dates.begin();
		assert(pos<dates.size());
		ar<int, 3> cur=dates[pos];
		string ans1=filler(cur[2], 2)+To_string(cur[2]);
		string ans2=filler(cur[1], 2)+To_string(cur[1]);
		string ans3=filler(cur[0], 4)+To_string(cur[0]);
		cout << ans1 << "." << ans2 << "." << ans3 << ".\n";
	}
	return 0;
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from datum.cpp:1:
datum.cpp: In function 'int main()':
datum.cpp:45:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   assert(pos<dates.size());
      |          ~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 6 ms 640 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 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 7 ms 640 KB Output is correct