Everyone has a geek spirit.

Source: Internet
Author: User

http://www.jisuanke.com/minicourse/59/438

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).

Date the display of each number on the electronic screen is as follows:

The number of strokes that can be learned from each number, such as 2 strokes is the number of strokes of 5,8 is 7, and so on. Everyone employee Xiao Ming saw the project start date D, but the project end date is not clear, only know the electronic screen on the project end date of the number of strokes required for m, can you help Xiao Ming figure out the time spent in project execution?

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.

Example 1

Input:

220150718302999123138

Output:

85-1

http://paste.ubuntu.com/11897447/
The end date is certainly later than the start date, and the program lets you calculate the duration of the number of days, so ans++, stroke number control program end

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespaceStd;typedefLong LongLL;intyear[ the], month2[ -], day[ +];ints[Ten] = {6,2,5,5,4,5,6,3,7,6}; Number of strokes required to save the first few numbersintmonth1[2][ -] = {0, to, -, to, -, to, -, to, to, -, to, -, to,0, to, in, to, -, to, -, to, to, -, to, -, to}; Month[0] Save is not a leap year the current month number of daysvoidinit () { for(intI=0; i< +; i++) Day[i]= s[i%Ten] + s[i/Ten]; The number of strokes required for the first day, the sum of the number of strokes required for 0 and 1 for(intI=0; i< -; i++) Month2[i]= s[i%Ten] + s[i/Ten]; The number of strokes required in the first month, December is the sum of the number of strokes required for 1 and 2 memset (year,0,sizeof(year));  for(intI=0; i< the; i++)    {        intm =i;  for(intj=0; j<4; J + +) {Year[i]+ = s[m%Ten]; Number of strokes required in the first few years 2015 is the sum of the number of strokes required for the digital 2,0,1,5 m/=Ten; }    }}intMain () {init (); intT, y, M, D, num, ans; scanf ("%d", &t);  while(T--)    {        intFlag =0; Ans=0; scanf ("%4d%2d%2d", &y, &m, &d); if(y% -==0|| (y%4==0) && (y% -!=0) ) is a leap year flag=1; scanf ("%d", &num);  while(true)        {            intNu = year[y] + month2[m] +Day[d]; The number of strokes required for the current dateif(Nu = =num) equals end while Break; if(y==2999&& m== A&& d== to) {ans= -1;  Break; } d++; Each time the d+1,ans+1 is added to the date and the number of strokes is the same as the input end while ANS++; if(Month1[flag][m] <d) {d-=Month1[flag][m]; Month < D, days start next month from 0, month m+1 m++; }             if(M > A) month is greater than 12, and the next year starts with {m-= A; Y++; if(y% -==0|| (y%4==0) && (y% -!=0)) Flag=1; ElseFlag=0; }} printf ("%d\n", ans); Output days}return 0;}

Everyone has a geek spirit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.