mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-07 08:30:43 +08:00
添加文本转换器代码
This commit is contained in:
13
others/C++/text converter/src/ROT13Converter.cpp
Normal file
13
others/C++/text converter/src/ROT13Converter.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "../include/ROT13Converter.hpp"
|
||||
|
||||
std::string ROT13Converter::convert(const std::string& input) {
|
||||
std::string result;
|
||||
for (char c : input) {
|
||||
if (isalpha(c)) {
|
||||
char base = isupper(c) ? 'A' : 'a';
|
||||
c = (c - base + 13) % 26 + base;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user