Baby Ming and phone number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1897 Accepted Submission(s): 490
Problem Description
Baby Ming collected lots of cell phone numbers, and he wants to sell them for money.
He thinks normal number can be sold for b yuan, while number with following features can be sold for a yuan.
1.The last five numbers are the same. (such as 123-4567-7777)
2.The last five numbers are successive increasing or decreasing, and the diffidence between two adjacent digits is 1. (such as 188-0002-3456)
3.The last eight numbers are a date number, the date of which is between Jar 1st, 1980 and Dec 31th, 2016. (such as 188-1888-0809,means August ninth,1888)
Baby Ming wants to know how much he can earn if he sells all the numbers.
Input
In the first line contains a single positive integer T, indicating number of test case.
In the second line there is a positive integer n, which means how many numbers Baby Ming has.(no two same phone number)
In the third line there are 2 positive integers a,b, which means two kinds of phone number can sell a yuan and b yuan.
In the next n lines there are n cell phone numbers.(|phone number|==11, the first number can’t be 0)
1≤T≤30,b<1000,0<a,n≤100,000
Output
How much Baby Nero can earn.
Sample Input
1
5
100000 1000
12319990212
11111111111
22222223456
10022221111
32165491212
Sample Output
302000
Source
BestCoder Round #69 (div.2)
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <time.h>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int INF=0x7fffffff;
const int MAX_N=10000;
int T;
long long n,a,b,x;
int yy[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int judge(long long t){
int c1=t%100000;
if(c1%11111==0)return 1;
for(int i=1234;i<=56789;i+=11111){
if(i==c1)return 1;
}
for(int i=43210;i<=98765;i+=11111){
if(i==c1)return 1;
}
// cout<<"fuck"<<endl;
int y=(t%100000000)/10000;
// cout<<"y"<<y<<endl;
if(y<1980||y>2016)return 0;
int m=t%10000/100;
// cout<<m<<endl;
if(m>12)return 0;
int d=t%100;
//cout<<d<<endl;
if(d<=0||d>31)return 0;
if(y%4!=0&&yy[m-1]>=d)return 1;
if(y%4==0){
if(m==2){
if(d<=29)return 1;
else return 0;
}
else{
if(yy[m-1]>=d)return 1;
}
}
return 0;
}
int main(){
cin>>T;
while(T--){
cin>>n>>a>>b;
long long ans=0;
for(int i=0;i<n;i++){
scanf("%lld",&x);
if(judge(x))ans+=a;
else ans+=b;
//cout<<judge(x)<<endl;
}
cout<<ans<<endl;
}
return 0;
}