Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

让switch或者elseif快些的办法

Posted by cooper at 2007-06-12 13:11:37 on Problem 1002
//字母连续的3个为一组,仅从'Q'以后错位一个,所以........
inline size_t parse(const string& raw)
{
    size_t result(0);
    size_t len = raw.length();
    char one_char;
    for(size_t i=0; i<len; ++i){
	one_char = raw[i];
	if (one_char > 'Q'){
	    result = result * 10 + (one_char-'B')/3 + 2;
	}
	else if (one_char >= 'A'){
	    result = result * 10 + (one_char-'A')/3 + 2;
	}
	else if (one_char >= '0')
	    result = result * 10 + one_char - '0';
    }
    return result;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator