hdu 5611 Baby Ming and phone number(模拟)
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
判断日期的时候比较麻烦,也懒得去优化了,还有会爆int,这个值得注意
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<math.h> 7 #include<algorithm> 8 #include<queue> 9 #include<set> 10 #include<bitset> 11 #include<map> 12 #include<vector> 13 #include<stdlib.h> 14 #include <stack> 15 using namespace std; 16 #define PI acos(-1.0) 17 #define max(a,b) (a) > (b) ? (a) : (b) 18 #define min(a,b) (a) < (b) ? (a) : (b) 19 #define ll long long 20 #define eps 1e-10 21 #define MOD 1000000007 22 #define N 100006 23 #define inf 1e12 24 ll n,a,b; 25 char s[16]; 26 bool judge(char *s){ 27 ll a=s[6]-'0'; 28 ll b=s[7]-'0'; 29 ll c=s[8]-'0'; 30 ll d=s[9]-'0'; 31 ll e=s[10]-'0'; 32 if( (a==b+1) && (b==c+1) && (c==d+1) && (d==e+1) ) return true; 33 if( (a==b-1) && (b==c-1) && (c==d-1) && (d==e-1) ) return true; 34 return false; 35 } 36 bool riqi(ll month,ll day){ 37 if(month == 3){ 38 if(day<1 || day>31) return false; 39 return true; 40 }else if(month==4){ 41 if(day<1 || day>30) return false; 42 return true; 43 }else if(month==5){ 44 if(day<1 || day>31) return false; 45 return true; 46 }else if(month==6){ 47 if(day<1 || day>30) return false; 48 return true; 49 }else if(month==7){ 50 if(day<1 || day>31) return false; 51 return true; 52 }else if(month==8){ 53 if(day<1 || day>31) return false; 54 return true; 55 }else if(month==9){ 56 if(day<1 || day>30) return false; 57 return true; 58 }else if(month==10){ 59 if(day<1 || day>31) return false; 60 return true; 61 }else if(month==11){ 62 if(day<1 || day>30) return false; 63 return true; 64 }else if(month==12){ 65 if(day<1 || day>31) return false; 66 return true; 67 } 68 } 69 bool riqi2(ll month,ll day){ 70 if(month<1 || month>12) return false; 71 if(month==1){ 72 if(day<1 || day>31) return false; 73 return true; 74 }else if(month==2){ 75 if(day<1 || day>29) return false; 76 return true; 77 }else if(month==3){ 78 if(day<1 || day>31) return false; 79 return true; 80 }else if(month==4){ 81 if(day<1 || day>30) return false; 82 return true; 83 }else if(month==5){ 84 if(day<1 || day>31) return false; 85 return true; 86 }else if(month==6){ 87 if(day<1 || day>30) return false; 88 return true; 89 }else if(month==7){ 90 if(day<1 || day>31) return false; 91 return true; 92 }else if(month==8){ 93 if(day<1 || day>31) return false; 94 return true; 95 }else if(month==9){ 96 if(day<1 || day>30) return false; 97 return true; 98 }else if(month==10){ 99 if(day<1 || day>31) return false; 100 return true; 101 }else if(month==11){ 102 if(day<1 || day>30) return false; 103 return true; 104 }else if(month==12){ 105 if(day<1 || day>31) return false; 106 return true; 107 } 108 } 109 bool riqi3(ll month,ll day){ 110 if(month<1 || month>12) return false; 111 if(month==1){ 112 if(day<1 || day>31) return false; 113 return true; 114 }else if(month==2){ 115 if(day<1 || day>28) return false; 116 return true; 117 }else if(month==3){ 118 if(day<1 || day>31) return false; 119 return true; 120 }else if(month==4){ 121 if(day<1 || day>30) return false; 122 return true; 123 }else if(month==5){ 124 if(day<1 || day>31) return false; 125 return true; 126 }else if(month==6){ 127 if(day<1 || day>30) return false; 128 return true; 129 }else if(month==7){ 130 if(day<1 || day>31) return false; 131 return true; 132 }else if(month==8){ 133 if(day<1 || day>31) return false; 134 return true; 135 }else if(month==9){ 136 if(day<1 || day>30) return false; 137 return true; 138 }else if(month==10){ 139 if(day<1 || day>31) return false; 140 return true; 141 }else if(month==11){ 142 if(day<1 || day>30) return false; 143 return true; 144 }else if(month==12){ 145 if(day<1 || day>31) return false; 146 return true; 147 } 148 } 149 150 bool cal(char *s){ 151 ll year = 0 , month = 0 , day = 0; 152 year = (s[3]-'0')*1000 + (s[4]-'0')*100 + (s[5]-'0')*10 +s[6]-'0'; 153 month = (s[7]-'0')*10 + s[8]-'0'; 154 day = (s[9]-'0') *10 + s[10]-'0'; 155 if(year == 1980){ 156 if(month>12 || month<1) return false; 157 if(month==1){ 158 if(day<1 || day>31) return false; 159 return true; 160 }else if(month == 2){ 161 if(day > 29 || day < 1) return false; 162 return true; 163 }else{ 164 if(riqi(month,day)) return true; 165 return false; 166 } 167 }else if(year == 2016){ 168 if(riqi2(month,day)) return true; 169 return false; 170 }else if(year>1980 && year<2016){ 171 if((year%4==0&&year%100!=0)||(year%400==0)){ 172 if(riqi2(month,day)) return true; 173 return false; 174 }else{ 175 if(riqi3(month,day)) return true; 176 return false; 177 } 178 }else{ 179 return false; 180 } 181 } 182 183 int main() 184 { 185 ll t; 186 scanf("%I64d",&t); 187 while(t--){ 188 scanf("%I64d",&n); 189 scanf("%I64d%I64d",&a,&b); 190 ll ans=0; 191 for(ll i=0;i<n;i++){ 192 scanf("%s",s); 193 if((s[6]==s[7]) && (s[6]==s[8]) && (s[6]==s[9]) && s[6]==s[10] ){ 194 ans+=a; 195 }else if(judge(s)){ 196 ans+=a; 197 }else if(cal(s)){ 198 ans+=a; 199 }else{ 200 ans+=b; 201 } 202 } 203 printf("%I64d ",ans); 204 } 205 return 0; 206 }