Baby Ming and phone number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 174 Accepted Submission(s): 60
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.
He thinks normal number can be sold for b
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
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
In the second line there is a positive integer n
In the third line there are 2
In the next n
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
题意:写题意很麻烦啊,直接给中文题面链接吧:中文题面
题解:模拟,注意判闰年;日,月的不能小于1。
代码如下:
#include<cstdio>
#include<cstring>
#define ll long long
char str[15];
int yunnian(int n)
{
if(n%400==0||(n%4==0&&n%100!=0))
return 1;
return 0;
}
int main()
{
int t,n,a,b,i;
ll sum;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%d%d",&a,&b);
sum=0;
while(n--)
{
scanf("%s",str);
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(str[6]==str[7]&&str[7]==str[8]&&str[8]==str[9]&&str[9]==str[10])
sum+=a;
else if(str[6]-1==str[7]&&str[7]-1==str[8]&&str[8]-1==str[9]&&str[9]-1==str[10])
sum+=a;
else if(str[6]+1==str[7]&&str[7]+1==str[8]&&str[8]+1==str[9]&&str[9]+1==str[10])
sum+=a;
else
{
int year=0,month=0,day=0;
year=(str[3]-'0')*1000+(str[4]-'0')*100+(str[5]-'0')*10+(str[6]-'0');
month=(str[7]-'0')*10+(str[8]-'0');
day=(str[9]-'0')*10+(str[10]-'0');
int sign=1;
if(year<1980||year>2016)
sign=0;
else
{
int cnt=yunnian(year);
if(cnt)
days[2]++;
if(month<1||month>12)
sign=0;
else
{
if(day>days[month]||day<1)
sign=0;
}
}
if(sign)
sum+=a;
else
sum+=b;
}
}
printf("%I64d\n",sum);
}
return 0;
}