problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::decode_the_slanted_ciphertext::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static string decodeCiphertext (string encodedText, int rows)
 
static string rtrim (string &s)
 去除字符串右边的空白符 [https://blog.csdn.net/tiandyoin/article/details/81508445] 更多...
 

详细描述

在文件 leetcode.h352 行定义.

成员函数说明

◆ decodeCiphertext()

string leetcode::decode_the_slanted_ciphertext::Solution::decodeCiphertext ( string  encodedText,
int  rows 
)
static

在文件 leetcode.cpp808 行定义.

808 {
809 if(encodedText.empty()) {
810 return "";
811 }
812 const int columns = encodedText.length() / rows;
813 auto *const table = new char *[rows];
814 for(int i = 0; i < rows; i++) {
815 table[i] = new char[columns - rows + 2];
816 for(int j = i; j - i < columns - rows + 2; j++) {
817 if(i * columns + j < encodedText.length()) {
818 table[i][j - i] = encodedText[i * columns + j];
819 } else {
820 table[i][j - i] = ' ';
821 }
822 }
823 }
824 auto oss = ostringstream();
825 for(int j = 0; j < columns - rows + 2; j++) {
826 for(int i = 0; i < rows; i++) {
827 oss << table[i][j];
828 }
829 }
830 string ans = oss.str();
831 for(int i = 0; i < rows; i++) {
832 delete[] table[i];
833 }
834 delete[] table;
835 return rtrim(ans);
836 }
static string rtrim(string &s)
去除字符串右边的空白符
Definition: leetcode.cpp:838

引用了 rtrim().

被这些函数引用 leetcode::decode_the_slanted_ciphertext::TEST().

◆ rtrim()

string leetcode::decode_the_slanted_ciphertext::Solution::rtrim ( string &  s)
static

去除字符串右边的空白符 [https://blog.csdn.net/tiandyoin/article/details/81508445]

作者
tiandyoin
参数
s要去除右边空白符的字符串
返回
去除了右边空白符的字符串

在文件 leetcode.cpp838 行定义.

838 {
839 for(int i = s.length() - 1; i >= 0; i--) {
840 if(s[i] != ' ') {
841 string ans = s.substr(0, i + 1);
842 return ans;
843 }
844 }
845 return s;
846 }

被这些函数引用 decodeCiphertext().


该类的文档由以下文件生成: