Everyone has a geek spirit .
Everyone company is a very encouraging geek spirit of the company, when there are important projects need to be on-line but too tight, and even need to be on the day of the launch, will often hang up the pirate flag to open the electronic date display, so that you can have a clearer sense of time, together to solve important projects. The Pirate's electronic screen displays a date in the form of YYYYMMDD (4-bit, 2-digit month, and 2-bit days).
Each number on the electronic screen of the date corresponds to the following image:
From the above figure, we can know the number of strokes per number, such as 2 strokes is 5,8 the number of strokes is 7, and so on. Everyone employee Xiao Ming saw the project start date D, but the project end date did not see clearly, only know the electronic screen on the project end date of the number of strokes required for m, you can help Xiao Ming figure out the time spent in the execution of the project.
Input format
There are multiple sets of input data. The first line enters an integer t (1≤t≤20), which represents a total of T-group data.
Next, each group of data 2 rows, a total of T * 2 rows. Enter a number-only string d for the first row of each group, indicating the project's start date, in the form YYYYMMDD. Enter a non-negative integer m (0≤m≤100) for the second row of each group, representing the number of strokes required for the item end date on the electronic screen. Enter a date to ensure legality.
Output format
Output a total of T-lines, one integer per line, representing the number of days that the group's data corresponds to the time spent executing the project. If the last meeting requirement end date is more than December 31, 2999 or no solution output-1, otherwise the output meets the required minimum solution.
Input:
2
20150718
29991231
38
Output:
-1
Problem Solving Ideas:
Direct violence can be. AC Code:
#include <bits/stdc++.h> using namespace std;
const int num[] = {6,2,5,5,4,5,6,3,7,6};
int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
Char str[10];
int a[10],n;
int y,m,d;
int check () {return num[y/1000]+num[(y/100)%10]+num[(Y/10)%10]+num[y%10]+num[m/10]+num[m%10]+num[d/10]+num[d%10];}
int check (int y) {if ((y%4==0&&y%100!=0) | | y%400==0) return 366;
return 365;
} void Next () {if (check (y) = = 366) month[2] = 29;
else month[2] = 28;
d++;
if (d > month[m]) d = 1,m++;
if (M > N) m = 1,y++;
} int main () {int T;
scanf ("%d", &t);
while (t--) {scanf ("%s%d", str,&n);
for (int i = 0; i < 8; i++) a[i] = str[i]-' 0 ';
y = a[0]*1000+a[1]*100+a[2]*10+a[3];
m = a[4]*10+a[5];
d = a[6]*10+a[7];
if (n>56 | | n<16) {puts ("-1");
Continue
} if (n = = Check ()) {puts ("0");
Continue
} if (y==2999 && m==12 && d==31) {puts ("-1"); Continue
} int ans = 0;
while (true) {next (); ans++;
printf ("%d%d%d\n", y,m,d);
if (n = = check ()) break;
if (y==2999 && m==12 && d==31) {ans =-1;
Break
}} printf ("%d\n", ans);
} return 0;
}