Baby Ming and phone number
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 373 Accepted Submission(s): 108
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 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
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
题目链接:点击打开链接
n个电话号码, 满足条件的可以卖a元, 其他号码卖b元, 计算可以卖的钱数. 条件: 1.后五位相等 2.后五位递增或递减 3.后8位是正确的日
期(1980.1.1 - 2016.12.31).
1 2条件容易判断, 第3个条件利用stl string的assign()处理, 直接比较即可判断.
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
int t, n, a, b;
string s;
bool Judge(string x)
{
int num = 0, cnt = 1;
for(int i = 3; i >= 0; --i) {
num += cnt * x[i];
cnt *= 10;
}
if(num % 400 == 0 || (num % 4 == 0 && num % 100 != 0)) return true;
return false;
}
int main(int argc, char const *argv[])
{
scanf("%d", &t);
while(t--) {
int num1 = 0, num2 = 0;
scanf("%d", &n);
scanf("%d%d", &a, &b);
for(int i = 0; i < n; ++i) {
cin >> s;
string y, m, d;
y.assign(s, 3, 4);
m.assign(s, 7, 2);
d.assign(s, 9, 2);
if(s[6] == s[7] && s[7] == s[8] && s[8] == s[9] && s[9] == s[10]) num1++;
else if(s[6] + 1 == s[7] && s[7] + 1 == s[8] && s[8] + 1 == s[9] && s[9] + 1 == s[10]) num1++;
else if(s[6] - 1 == s[7] && s[7] - 1 == s[8] && s[8] - 1 == s[9] && s[9] - 1 == s[10]) num1++;
else if(y >= "1980" && y <= "2016") {
if(m == "01" && d <= "31" && d >= "01") num1++;
else if(m == "03" && d <= "31" && d >= "01") num1++;
else if(m == "05" && d <= "31" && d >= "01") num1++;
else if(m == "07" && d <= "31" && d >= "01") num1++;
else if(m == "08" && d <= "31" && d >= "01") num1++;
else if(m == "10" && d <= "31" && d >= "01") num1++;
else if(m == "12" && d <= "31" && d >= "01") num1++;
else if(m == "04" && d <= "30" && d >= "01") num1++;
else if(m == "06" && d <= "30" && d >= "01") num1++;
else if(m == "09" && d <= "30" && d >= "01") num1++;
else if(m == "11" && d <= "30" && d >= "01") num1++;
else if(m == "02" && ((Judge(y) && d <= "29" && d >= "01") || (!Judge(y) && d <= "28" && d >= "01"))) num1++;
else num2++;
}
else num2++;
}
printf("%lld\n", 1ll * num1 * a + 1ll * num2 * b);
}
return 0;
}