add: 220322 [cpp]

This commit is contained in:
Lam Haoyin 2022-03-22 14:19:11 +08:00
parent ab12649430
commit a8f1083ae7
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 19 additions and 1 deletions

18
cpp/2203/220322.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <string>
#include <iostream>
class Solution {
public:
static std::string getSmallestString(int n, int k) {
if (n == k)
return std::string(n, 'a');
if (k - n < 26)
return std::string(n - 1, 'a') + static_cast<char>('a' + (k - n));
return getSmallestString(n - 1, k - 26) + 'z';
}
};
int main() {
std::cout << Solution::getSmallestString(5, 73);
return 0;
}

View File

@ -3,4 +3,4 @@ PROJECT(2203)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2203 220322-CN.cpp)
ADD_EXECUTABLE(2203 220322.cpp)