Computing customers (everyone has the spirit of geeks)
Renren is a company that encourages geeks very much. When there is an important project that needs to be launched, but the time is too short, or even needs to be released on the same day, the pirate flag is often suspended to enable the electronic date display, this allows you to work together on important projects with a clearer perception of time. The date displayed on the e-screen below the pirate flag is YYYYMMDD (the year occupies 4 places, the month occupies 2 places, and the number of days occupies 2 places ).
The display of each number on the date electronic screen is as follows:
The input format shows the number of strokes corresponding to each number. For example, if the number of strokes in 2 is 5, the number of strokes in 8 is 7. James, an employee of everyone, saw the project launch date d, but the project end date was not clear. He only knew that the number of strokes required for the project end date on the electronic screen was m, can you help James calculate the number of days of project execution?
There are multiple groups of input data. In the first line, enter an integer T (1 ≤ T ≤ 20), indicating a total of T groups of data.
Next, there are two rows of data in each group, T * 2 rows in total. Enter a string d with a length of 8 in the first line of each group, indicating the project start date in the format of YYYYMMDD. Enter a non-negative integer m (0 ≤ m ≤ 100) in the second row of each group, indicating the number of strokes required for the end date of the project on the electronic screen. The input date must be valid.
Output Format
A total of T rows are output, each row has an integer, indicating the number of days that the project execution of the group of data takes. If the last compliant end date exceeds December 31, 2999 or no solution is available,-1 is output; otherwise, the minimum compliant solution is output.
Example 1
Input:
220150718302999123138
Output:
85-1
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int N = 1005;int num[]={6,2,5,5,4,5,6,3,7,6};int getNum(int yy,int mm,int dd){ int sum=0; for(int i=1; i<=4; i++) { sum+=num[yy%10]; yy/=10; } sum+=num[mm%10]; mm/=10; sum+=num[mm%10]; sum+=num[dd%10]; dd/=10; sum+=num[dd%10]; return sum;}int main(){ int T,sum,n,date1[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&sum); int yy,mm,dd,ans=0; yy=n/10000; mm=(n%10000)/100; dd=n%100; bool flag=0; for(int tyy=yy,tmm=mm,tdd=dd ; yy<=2999; yy++) { if(yy%400==0||yy%100!=0&&yy%4==0) date1[2]=29; else date1[2]=28; for(mm=(yy==tyy)?tmm:1; mm<=12; mm++) { for(dd=(yy==tyy&&mm==tmm)?tdd:1; dd<=date1[mm]; dd++) { if(getNum(yy,mm,dd)==sum) { flag=1; break; } ans++; } if(flag)break; } if(flag)break; }//printf("%d %d %d\n",yy,mm,dd); if(flag==0)ans=-1; printf("%d\n",ans); } return 0;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.