Submission #238642

# Submission time Handle Problem Language Result Execution time Memory
238642 2020-06-12T08:56:08 Z Vankeca Datum (COCI20_datum) C++14
50 / 50
61 ms 504 KB
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
char day1[2], month1[2], year1[4], day2[2], month2[2], year2[4];
int d1,m1,yne1;
///----------------------------------------------
void read()
{
	char dot;
	cin>>day1[0]>>day1[1];
	cin>>dot;
	cin>>month1[0]>>month1[1];
	cin>>dot;
	cin>>year1[0]>>year1[1]>>year1[2]>>year1[3];
	cin>>dot;
}
///----------------------------------------------
void convert_st()
{
	d1=int(day1[0]-'0')*10+int(day1[1]-'0');
	m1=int(month1[0]-'0')*10+int(month1[1]-'0');
	yne1=int(year1[0]-'0')*1000+int(year1[1]-'0')*100+int(year1[2]-'0')*10+int(year1[3]-'0');
}
///----------------------------------------------
void construct_date(int y)
{
	int i=3;
	while(y>=0 && i>=0)
	{
		year2[i]=char(y%10+'0');
		y/=10;
		i--;
	}
	day2[0]=year2[3]; day2[1]=year2[2];
	month2[0]=year2[1]; month2[1]=year2[0];
    //cout<<day2[0]<<day2[1]<<"."<<month2[0]<<month2[1]<<"."<<year2[0]<<year2[1]<<year2[2]<<year2[3]<<endl;
}
///----------------------------------------------
int convert_dec(int k)
{
	if(k==1)
	{
		return int(day2[0]-'0')*10+int(day2[1]-'0');
	}
	if(k==2)
	{
		return int(month2[0]-'0')*10+int(month2[1]-'0');
	}
	if(k==3)
	{
		return int(year2[0]-'0')*1000+int(year2[1]-'0')*100+int(year2[2]-'0')*10+int(year2[3]-'0');
	}
}
///----------------------------------------------
bool check()
{
	int d=convert_dec(1), m=convert_dec(2), y=convert_dec(3);
	if(d==0 || m==0)return false;
	if(d>31 || m>12)return false;
	if(d==31 && (m==2 || m==4 || m==6 || m==9 || m==11))return false;
	if(d==30 && m==2)return false;
	if(d==29 && m==2)
	{
		if(y%4!=0)return false;
	}
	if(m<m1 && y==yne1)return false;
	if(d<=d1 && m<=m1 && y==yne1)return false;
	return true;
}
///----------------------------------------------
void solve()
{
	convert_st();
	construct_date(yne1);
	int i=yne1;
	//cout<<i<<endl;
	while(check()==false)
	{
		i++;
		construct_date(i);
	}
	cout<<day2[0]<<day2[1]<<"."<<month2[0]<<month2[1]<<"."<<year2[0]<<year2[1]<<year2[2]<<year2[3]<<"."<<endl;
}
///----------------------------------------------
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	while(n--)
	{
		read();
		solve();
	}

	return 0;
}

Compilation message

datum.cpp: In function 'int convert_dec(int)':
datum.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 55 ms 504 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 61 ms 420 KB Output is correct