| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
来个191B的小代码,不用各种if比较字符获得的积分可以表示为两部分的和
ACMPerk = a * Actual /2 + b * Actual
F时: a = 4, b = 0, b在首位,剩下3位存a,则二进制为0100
B时: a = 3, b = 0 0011
Y时: a = 0, b = 1 1000
因此以2进制位来表示不同情况时的ab,做一个表出来,也就是{3, 4, 8}
BFY三个字母的ascii码除以十,刚好分别是678,这个值作为索引查表。
main() {
char s[200], c;
int m = 0, d, p[3] = { 3, 4, 8 }, q;
while (scanf("%s", s) && *s != 35) {
if (s[0] == '0') {
printf("%d\n", m);
m = 0;
}
else {
scanf("%*s %d %c", &d, &c);
q = p[c / 10 - 6];
m += ((q & 7)*d + 1) / 2 + q / 8 * (d>500 ? d : 500);
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator