답안 #299152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299152 2020-09-14T14:08:03 Z quanmcvn Datum (COCI20_datum) C++14
50 / 50
6 ms 896 KB
#include <bits/stdc++.h>
#define fff "main"
#define For(i,a,b) for (auto i = a; i < b; ++i)
#define pb push_back
#define en cout << '\n';
using namespace std;

typedef signed long long int ll;
typedef std::vector<ll> vll;

ll n;
string a[10000];

vll years_palind;
vector<pair<ll,string> > value;

string palind(ll x){
	string res = "****";
	For (i,0,4){
		res[i] = char(x % 10 + '0');
		x /= 10;
	}
	return res;
}

ll day_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

string cvt(ll x, ll dig){
	string res; res.resize(dig);
	For (i,0,dig){
		res[dig - 1 - i] = char(x % 10 + '0');
		x /= 10;
	}
	return res;
}

bool comp_date (string lhs, string rhs){ // less
	if (lhs == rhs) return false;
	string lmm = lhs.substr(2,2);
	string rmm = rhs.substr(2,2);
	For (i,0,2){
		if (lmm[i] != rmm[i]) return lmm[i] < rmm[i];
	}
	string ldd = lhs.substr(0,2);
	string rdd = rhs.substr(0,2);
	For (i,0,2){
		if (ldd[i] != rdd[i]) return ldd[i] < rdd[i];
	}
}

ll po[] = {1,10,100,1000};

int main()
{
//	if (fopen(fff".inp","r")) {
//	freopen(fff".inp","r",stdin);
//	freopen(fff".out","w",stdout);
//	}
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	For (i,0,10000){
		string ddmm = palind(i);
		ll dd = (ddmm[0] - '0') * 10 + ddmm[1] - '0';
		ll mm = (ddmm[2] - '0') * 10 + ddmm[3] - '0';
		if (dd > 31 || dd < 1) continue;
		if (mm > 12 || mm < 1) continue;
		if (i % 4 == 0 && mm == 2) {
			if (dd > 29) continue;
		}
		else if (dd > day_in_month[mm]) continue;
		years_palind.pb(i);
		value.pb({i,cvt(dd,2) + cvt(mm,2)});
	}
	cin >> n;
	while (n--){
		string s; cin >> s;
		string ddmm = s.substr(0,2) + s.substr(3,2);
		string yyyy = s.substr(6,4); ll yy = 0;
		For (i,0,4){
			yy += (yyyy[i] - '0') * po[3 - i];
		}
		ll id = lower_bound(years_palind.begin(),years_palind.end(),yy) - years_palind.begin();
		if (years_palind[id] == yy) {
			if (!comp_date(ddmm,value[id].second)) id = upper_bound(years_palind.begin(),years_palind.end(),yy) - years_palind.begin();
		}
		cout << value[id].second.substr(0,2) << '.' << value[id].second.substr(2,2) << '.' << cvt(years_palind[id],4) << '.';
		en;
	}
    return 0;
}

Compilation message

datum.cpp: In function 'bool comp_date(std::string, std::string)':
datum.cpp:39:29: warning: control reaches end of non-void function [-Wreturn-type]
   39 |  string lmm = lhs.substr(2,2);
      |                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 640 KB Output is correct
2 Correct 6 ms 896 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 6 ms 896 KB Output is correct