HDOJ--5611(Baby Ming and phone number)(闰年)

16 篇文章 0 订阅
15 篇文章 0 订阅

Baby Ming and phone number

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1675    Accepted Submission(s): 437


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)

1T30,b<1000,0<a,n100,000
 

Output
How much Baby Nero can earn.
 

Sample Input
  
  
1 5 100000 1000 12319990212 11111111111 22222223456 10022221111 32165491212
 

Sample Output
  
  
302000
注意:这题要考虑闰年问题,4年一闰,百年不闰,400年再闰。
坑点:这题的最后结果竟然超int范围,要用长整形。
My  solution:

/*2016.3.12*/

#include<stdio.h>
#include<string.h>
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},num[14];
char s[15];
int a,b;
int judge()
{
	int  i,j,k,t=0,year1=1980,year2=2016,h1,h2;
	for(i=8;i<=11;i++)//判断后5位数字相等
	{
		if(num[i]!=num[i-1])
		break;	
	}
	if(i==12)
	return 1;
	for(i=8;i<=11;i++) //判断后5位数字递增 
	{
		if((num[i]-num[i-1])!=1)
		break;
	}
	if(i==12)
	return 1;
	for(i=8;i<=11;i++)//判断后5位数字递减 
	{
		if((num[i-1]-num[i])!=1)
		break;
	}
	if(i==12)
	return 1;
	k=num[4]*1000+num[5]*100+num[6]*10+num[7];
	if(k%4==0&&k%100!=0||k%400==0)//是不是闰年 
	{
		month[2]+=1;
		t=1;
	}
	h1=num[8]*10+num[9];
	h2=num[10]*10+num[11];
	if(year1<=k&&k<=year2)//判断年份有没有超限 
	{
		if(h1>0&&h1<=12)//判断月份有没有超限
		{
				if(month[h1]>=h2)//判断日期有没有超限
			{
				month[2]-=t;//恢复二月天数 
				return 1;
			}
		}
	}
	month[2]-=t;
	return 0;
}
int main()
{
	int t,i,j,k,n;
	long long ans=0;
	scanf("%d",&t);
	while(t--)
	{
		ans=0;
		scanf("%d",&n);
		scanf("%d%d",&a,&b);
		for(i=1;i<=n;i++)
		{
			scanf("%s",s+1);
			for(j=1;j<=11;j++)
		    num[j]=s[j]-'0';
		    if(judge())
		    ans+=a;
		    else
		    ans+=b; 
		}
		printf("%I64d\n",ans);	
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值