Hdu 5611 Baby Ming and phone number【日期计算等等】
2016-03-12 16:02
405 查看
Baby Ming and phone number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1656 Accepted Submission(s): 434
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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
[align=left]Output[/align]
How much Baby Nero can earn.
[align=left]Sample Input[/align]
1
5
100000 1000
12319990212
11111111111
22222223456
10022221111
32165491212
[align=left]Sample Output[/align]
302000
题意:
给出一定的条件,满足条件的可以卖a元,否则b元,问这个人能赚多少钱。
题解:
需要完全模拟题目的条件,另外日期计算的时候注意细节的考虑,比如闰年等
#include<stdio.h>
typedef long long ll;
int x[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int abs(int x)
{
return x<0?-x:x;
}
int fun(int x)
{
return x%4==0&&x%100!=0||x%400==0;
}
bool one(char s[])
{
for(int i=7;i<11;++i)
{
if(s[i]!=s[i-1])
{
return 0;
}
}
return 1;
}
bool two(char s[])
{
for(int i=7;i<10;++i)
{
if(s[i]-s[i-1]!=s[i+1]-s[i]||abs(s[i]-s[i-1])!=1)
{
return 0;
}
}
return 1;
}
bool three(char s[])
{
int year=0,month=0,day=0;
for(int i=3;i<11;++i)
{
if(i<7)
{
year=year*10+(s[i]-'0');
}
else if(i<9)
{
month=month*10+(s[i]-'0');
}
else
{
day=day*10+(s[i]-'0');
}
}
if(year<1980||year>2016||month==0||month>12||day==0||day>31)
//不符合日期的规则
{
return 0;
}
if(month==2)//讨论二月
{
int tp=fun(year);//判断闰年
return day<=x[month]+tp;
}
else//其他月份
{
return day<=x[month];
}
}
bool judge(char s[])
{
return one(s)||two(s)||three(s);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ll n,a,b;
scanf("%I64d%I64d%I64d",&n,&a,&b);
ll ans=0;char s[15];
while(n--)
{
scanf("%s",s);
ans+=judge(s)?a:b;
}
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- Java中常用的网站
- java获取图片朝向并旋转
- RAID的使用详解
- list排序
- java.util.Timer类可以实现多线程一样的功能
- Android手动打包
- [leetcode 298] Binary Tree Longest Consecutive Sequence---求二叉树连续序列的长度
- 1014-34-首页15-计算原创微博的frame------计算cell的高度---计算 UILabel 的 CGSize 的方法
- 非对称加密(RSA)示例
- 电脑装两个jdk,怎么进行转换!
- react.js-05-children遍历数组组件
- 大整数类BigInteger
- 小学二年级四则运算
- 二柱子四则运算--第二部
- CSS——元素分类
- ubuntu 下截图与快捷键设置
- mongodb - 查看数据库状态
- json
- ext js 学习系列 二 MVC 框架的搭建 .
- [从头学数学] 第135节 整式的乘法与因式分解 小结与复习题