Submission #845436

# Submission time Handle Problem Language Result Execution time Memory
845436 2023-09-06T13:36:46 Z vjudge1 Datum (COCI20_datum) C++17
10 / 50
92 ms 460 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()

vector<int> t{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int toInt(string s){
	int ans=0, cur=1;
	for(int i=s.size()-1; i>=0; i--){
		ans+=cur*(s[i]-'0');
		cur*=10;
	}
	return ans;
}

string toString4(int a){
	string s;
	for(int i=0; i<4; i++){
		s.push_back((a%10)+'0');
		a/=10;
	}
	reverse(all(s));
	return s;
}

string toString2(int a){
	string s;
	for(int i=0; i<2; i++){
		s.push_back((a%10)+'0');
		a/=10;
	}
	reverse(all(s));
	return s;
}

int isValid(int y){
	string s=toString4(y);
	int d=(s[3]-'0')*10+s[2]-'0', m=(s[1]-'0')*10+s[0]-'0';
	if(d!=0 && m!=0 && d<=t[m] && (d!=29 || m!=2 || y%4!=0)) return 1;
	else return 0;
}

int main(){
	int t;
	cin>>t;

	while(t--){
		string s;
		cin>>s;

		int d=(s[9]-'0')*10+s[8]-'0', m=(s[7]-'0')*10+s[6]-'0', y=toInt(string(s.begin()+6, s.begin()+10));
		int dcur=(s[0]-'0')*10+s[1]-'0', mcur=dcur=(s[3]-'0')*10+s[4]-'0';

		if(isValid(y) && m>mcur || (m==mcur && d>dcur)) 
			cout<<toString2(d)<<'.'<<toString2(m)<<'.'<<toString2(m)<<'.'<<toString2(d)<<'.'<<endl;
		else{
			for(int i=y+1; i<10'000; i++){
				if(isValid(i)){
					string ans=toString4(i);
					cout<<ans[3]<<ans[2]<<'.'<<ans[1]<<ans[0]<<'.'<<ans<<'.'<<endl;
					break;
				}
			}
		}
	}
}

Compilation message

datum.cpp: In function 'int main()':
datum.cpp:57:17: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   57 |   if(isValid(y) && m>mcur || (m==mcur && d>dcur))
      |      ~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Incorrect 85 ms 348 KB Output isn't correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 92 ms 460 KB Output isn't correct