-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add excel sheet column title * impl excel sheet column title
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "TestHelper.h" | ||
#include "problem.h" | ||
#include "solution.h" | ||
|
||
using namespace std; | ||
|
||
IMPLEMENT_PROBLEM_CLASS( | ||
PExcelSheetColTitle, 168, DIFFI_EASY, TOPIC_ALGORITHMS, | ||
"Excel Sheet Column Title", | ||
"Given an integer columnNumber, return its corresponding column title as " | ||
"it appears in an Excel sheet.", | ||
{"Math"}); | ||
|
||
class SExcelSheetColTitle : public ISolution { | ||
public: | ||
size_t problemId() const override { return 168; } | ||
string name() const override { | ||
return ("Solution for " + string("Excel Sheet Column Title")); | ||
} | ||
string location() const override { return __FILE_NAME__; } | ||
int test() const override { | ||
return testHelper<int, string>( | ||
{1, 28, 701}, {"A", "AB", "ZY"}, | ||
[this](auto input) { return this->convertToTitle(input); }); | ||
}; | ||
int benchmark() const override { return 0; } | ||
|
||
private: | ||
string convertToTitle(int columnNumber) const { | ||
string res = ""; | ||
|
||
while (columnNumber) { | ||
columnNumber--; | ||
int mod = columnNumber % 26; | ||
res = char('A' + mod) + res; | ||
columnNumber /= 26; | ||
} | ||
|
||
return res; | ||
} | ||
}; |
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