Title Description
Alice writes a date on a piece of paper in the form MM-DD, where MM and DD are two digits representing the month and day, respectively, but the date does not necessarily exist. However, the date does not necessarily exist. Alice asks Bob to change a number of digits so that the date exists. Help Bob figure out the minimum number of digits he needs to change.
For the purpose of this question, we consider February to be fixed at 28 days.
importation
One five-character line onlystring (computer science), denoted MM-DD.
exports
One integer on one line only, indicating the answer.
Sample Inputs and Outputs
Input #1
03-32
Output #1
1
Enter #2.
02-39
Output #2
1
Enter #3.
67-89
Output #3
2
Instructions/Hints
[Input/Output Sample 1 Explanation]
There are more than one way to change this, and one of those ways is to read: 03-22.
[Input/Output Sample 2 Explanation]
One way to change it is: 02-09.
[Input/Output Sample 3 Explanation]
One way to change this is: 07-09.
[Data Size and Conventions] For 100% data: MM and DD must be 4 digits.
-
#include<bits/stdc++.h>
-
using namespace std;
-
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
-
int main(){
-
int n,m,num=0,mi=INT_MAX;
-
char a;
-
cin>>n>>a>>m;
-
if(n==0){//Special verdict attention to test points 00-00 and 00-31
-
num++;
-
n=1;
-
}
-
if(m==0){
-
num++;
-
m=1;
-
}
-
if(n>12){
-
if(n%10<=2){
-
if(month[10+n%10]>=m){
-
cout<<1;
-
return 0;
-
}
-
}
-
if(n%10!=0){
-
num++;
-
if(month[n%10]<m){
-
num++;
-
}
-
cout<<num;
-
return 0;
-
}else if(n/10>=2){
-
num+=2;
-
if(month[n%10]<m){
-
num++;
-
}
-
cout<<num;
-
return 0;
-
}
-
}
-
if(month[n]<m){
-
num++;
-
}
-
cout<<num;
-
return 0;
-
}