428 million garlic customers (everyone has a geek spirit-date issues), geek plan

Source: Internet
Author: User

428 million garlic customers (everyone has a geek spirit-date issues), geek plan

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:


Input Format

We can know the number of strokes corresponding to each number. For example, the number of strokes in 2 is 7, and 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


Direct violence



#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXT (20+10)#define MAXN (10+10)typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};  int g[20]={6,2,5,5,4,5,6,3,7,6};int is_l(int y)  {      if (y%4==0&&y%100!=0) return 366;      if (y%400==0) return 366;return 365;  }  char s[MAXN];int A[MAXN];int T,m;int d1,m1,Y1;void next(){if (is_l(Y1)==366) a[2]=29;else a[2]=28;d1++;if (d1>a[m1]) d1=1,m1++;if (m1>12) m1=1,Y1++;}int count(){return g[Y1/1000]+g[(Y1/100)%10]+g[(Y1/10)%10]+g[Y1%10]+g[m1/10]+g[m1%10]+g[d1/10]+g[d1%10];}int main(){//freopen("num.in","r",stdin);//freopen("num.out","w",stdout);cin>>T;while(T--){cin>>s>>m;Rep(i,8) A[i+1]=s[i]-'0';Y1=A[1]*1000+A[2]*100+A[3]*10+A[4];m1=A[5]*10+A[6];d1=A[7]*10+A[8];//cout<<Y1<<' '<<m1<<' '<<d1<<endl;if (m>56||m<16) {cout<<"-1"<<endl;continue;}//cout<<count()<<endl;if (m==count()) {cout<<"0"<<endl;continue;}if (Y1==2999&&m1==12&&d1==31) {cout<<"-1"<<endl;continue;}int ans=0;while (1){next();ans++;//cout<<Y1<<' '<<m1<<' '<<d1<<endl;if (m==count()) break;if (Y1==2999&&m1==12&&d1==31) {ans=-1;break;}}cout<<ans<<endl;}return 0;}





Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.