Skip to content

Instantly share code, notes, and snippets.

@shnya
Created January 4, 2011 17:54
Show Gist options
  • Save shnya/765108 to your computer and use it in GitHub Desktop.
Save shnya/765108 to your computer and use it in GitHub Desktop.
SRM 344 Div2 Level 1
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