Created
January 4, 2011 17:54
-
-
Save shnya/765108 to your computer and use it in GitHub Desktop.
SRM 344 Div2 Level 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chessboard | |
{ | |
public: | |
string changeNotation(string cell) | |
{ | |
ostringstream oss; | |
if(cell[0] >= 'a' && cell[0] <= 'h'){ | |
int c = static_cast<int>(cell[0]) - 'a' + 1; | |
int n = static_cast<int>(cell[1]) - '1'; | |
oss << (n * 8 + c); | |
}else{ | |
int n = strtol(cell.c_str(), NULL, 0); | |
int l = (n - 1) / 8 + 1; | |
char c = static_cast<char>(n - (l -1) * 8) + 'a' - 1; | |
oss << c << l; | |
} | |
return oss.str(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment