답안 #373056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373056 2021-03-03T08:20:02 Z Nimbostratus Datum (COCI20_datum) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cln(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int int
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5 + 5;
const int inf = 1e9;
const int mod = 1e9+7;

class date {
	public:
	string sday,smonth,syear;
	int day,month,year;
	date() {
		day = inf;
		month = inf;
		year = inf;
	}
	date(string& sd,string& sm,string& sy) {
		day = stoi(sd);
		month = stoi(sm);
		year = stoi(sy);
		sday = sd;
		smonth = sm;
		syear = sy;
	}
	friend bool operator < (date& x , date& y) {
		if(x.year < y.year) return true;
		if(x.year > y.year) return false;
		if(x.month < y.month) return true;
		if(x.month > y.month) return false;
		return x.day < y.day;
	}
	friend bool operator == (date& x , date& y) {
		return x.year == y.year and x.month == y.month and x.day == y.day;
	}
	friend bool operator <= (date& x , date& y) {
		return x < y or x == y;
	}
};

int n;
string s;
vector<date> vec;
vector<int> days;



bool isvalid(date& x) {
	if(x.month == 2 && x.day == 29) return x.year % 4 == 0;
	if(x.month > 12 or x.month <= 0) return false;
	if(x.day > days[x.month] or x.day <= 0) return false;
	return true;
}

date datify() {
	string day,month,year;
	int i=0;
	for(;i<s.size() && s[i] != '.';i++)
		day += s[i];
	i++;
	for(;i<s.size() && s[i] != '.';i++)
		month += s[i];
	i++;
	for(;i<s.size() && s[i] != '.';i++)
		year += s[i];
	return date(day,month,year);
}

int32_t main () {
	freopen("in","r",stdin); freopen("out","w",stdout);
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
	for(char i='0';i<='3';i++)
		for(char j='0';j<='9';j++)
			for(char k='0';k<='1';k++)
				for(char m='0';m<='9';m++) {
					string day = string()+i+j;
					string month = string()+k+m;
					string year = day + month;
					reverse(all(year));
					date d(day,month,year);
					if(isvalid(d)) {
						vec.pb(d);
					}
				}
	sort(all(vec));
	/*for(date x : vec) {
		cout << x.day << "." << x.month << "." << x.year << "." << endl;
	}*/
	//cout << endl;
	cin >> n;
	while(n--) {
		cin >> s;
		date x = datify();
		int i;
		for(i=0;i<vec.size() and vec[i]<=x;i++);
		date d = vec[i];
		cout << d.sday << "." << d.smonth << "." << d.syear << "." << endl;
	}
}	
	
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cln(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int int
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5 + 5;
const int inf = 1e9;
const int mod = 1e9+7;

class date {
	public:
	string sday,smonth,syear;
	int day,month,year;
	date() {
		day = inf;
		month = inf;
		year = inf;
	}
	date(string& sd,string& sm,string& sy) {
		day = stoi(sd);
		month = stoi(sm);
		year = stoi(sy);
		sday = sd;
		smonth = sm;
		syear = sy;
	}
	friend bool operator < (date& x , date& y) {
		if(x.year < y.year) return true;
		if(x.year > y.year) return false;
		if(x.month < y.month) return true;
		if(x.month > y.month) return false;
		return x.day < y.day;
	}
	friend bool operator == (date& x , date& y) {
		return x.year == y.year and x.month == y.month and x.day == y.day;
	}
	friend bool operator <= (date& x , date& y) {
		return x < y or x == y;
	}
};

int n;
string s;
vector<date> vec;
vector<int> days;



bool isvalid(date& x) {
	if(x.month == 2 && x.day == 29) return x.year % 4 == 0;
	if(x.month > 12 or x.month <= 0) return false;
	if(x.day > days[x.month] or x.day <= 0) return false;
	return true;
}

date datify() {
	string day,month,year;
	int i=0;
	for(;i<s.size() && s[i] != '.';i++)
		day += s[i];
	i++;
	for(;i<s.size() && s[i] != '.';i++)
		month += s[i];
	i++;
	for(;i<s.size() && s[i] != '.';i++)
		year += s[i];
	return date(day,month,year);
}

int32_t main () {
	//freopen("in","r",stdin); freopen("out","w",stdout);
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
	for(char i='0';i<='3';i++)
		for(char j='0';j<='9';j++)
			for(char k='0';k<='1';k++)
				for(char m='0';m<='9';m++) {
					string day = string()+i+j;
					string month = string()+k+m;
					string year = day + month;
					reverse(all(year));
					date d(day,month,year);
					if(isvalid(d)) {
						vec.pb(d);
					}
				}
	sort(all(vec));
	/*for(date x : vec) {
		cout << x.day << "." << x.month << "." << x.year << "." << endl;
	}*/
	//cout << endl;
	cin >> n;
	while(n--) {
		cin >> s;
		date x = datify();
		int i;
		for(i=0;i<vec.size() and vec[i]<=x;i++);
		date d = vec[i];
		cout << d.sday << "." << d.smonth << "." << d.syear << "." << endl;
	}
}	
	

Compilation message

datum.cpp: In function 'date datify()':
datum.cpp:69:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp:72:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp:75:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp: In function 'int32_t main()':
datum.cpp:107:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for(i=0;i<vec.size() and vec[i]<=x;i++);
      |           ~^~~~~~~~~~~
datum.cpp: At global scope:
datum.cpp:128:11: error: redefinition of 'const int maxn'
  128 | const int maxn = 2e5 + 5;
      |           ^~~~
datum.cpp:16:11: note: 'const int maxn' previously defined here
   16 | const int maxn = 2e5 + 5;
      |           ^~~~
datum.cpp:129:11: error: redefinition of 'const int inf'
  129 | const int inf = 1e9;
      |           ^~~
datum.cpp:17:11: note: 'const int inf' previously defined here
   17 | const int inf = 1e9;
      |           ^~~
datum.cpp:130:11: error: redefinition of 'const int mod'
  130 | const int mod = 1e9+7;
      |           ^~~
datum.cpp:18:11: note: 'const int mod' previously defined here
   18 | const int mod = 1e9+7;
      |           ^~~
datum.cpp:132:7: error: redefinition of 'class date'
  132 | class date {
      |       ^~~~
datum.cpp:20:7: note: previous definition of 'class date'
   20 | class date {
      |       ^~~~
datum.cpp:164:5: error: redefinition of 'int n'
  164 | int n;
      |     ^
datum.cpp:52:5: note: 'int n' previously declared here
   52 | int n;
      |     ^
datum.cpp:165:8: error: redefinition of 'std::string s'
  165 | string s;
      |        ^
datum.cpp:53:8: note: 'std::string s' previously declared here
   53 | string s;
      |        ^
datum.cpp:166:14: error: redefinition of 'std::vector<date> vec'
  166 | vector<date> vec;
      |              ^~~
datum.cpp:54:14: note: 'std::vector<date> vec' previously declared here
   54 | vector<date> vec;
      |              ^~~
datum.cpp:167:13: error: redefinition of 'std::vector<int> days'
  167 | vector<int> days;
      |             ^~~~
datum.cpp:55:13: note: 'std::vector<int> days' previously declared here
   55 | vector<int> days;
      |             ^~~~
datum.cpp:171:6: error: redefinition of 'bool isvalid(date&)'
  171 | bool isvalid(date& x) {
      |      ^~~~~~~
datum.cpp:59:6: note: 'bool isvalid(date&)' previously defined here
   59 | bool isvalid(date& x) {
      |      ^~~~~~~
datum.cpp:178:6: error: redefinition of 'date datify()'
  178 | date datify() {
      |      ^~~~~~
datum.cpp:66:6: note: 'date datify()' previously defined here
   66 | date datify() {
      |      ^~~~~~
datum.cpp: In function 'date datify()':
datum.cpp:181:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  181 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp:184:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  184 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp:187:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  187 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp: At global scope:
datum.cpp:192:9: error: redefinition of 'int32_t main()'
  192 | int32_t main () {
      |         ^~~~
datum.cpp:80:9: note: 'int32_t main()' previously defined here
   80 | int32_t main () {
      |         ^~~~
datum.cpp: In function 'int32_t main()':
datum.cpp:219:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  219 |   for(i=0;i<vec.size() and vec[i]<=x;i++);
      |           ~^~~~~~~~~~~
datum.cpp: In function 'int32_t main()':
datum.cpp:81:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   81 |  freopen("in","r",stdin); freopen("out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~
datum.cpp:81:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   81 |  freopen("in","r",stdin); freopen("out","w",stdout);
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~