在C 中乘以两个char阵列
Multiplying two char arrays in C++
我正在尝试乘以两个char阵列row_index
和col_index
,这是我的row_index
和col_index
:
char row_index[20] = { '1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','L' };
char col_index[10] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K' };
因此,输出为 CSTRING输出[200] = {'a1','b1','c1',...,'kl'}
是否有执行此类任务的智能/有效方法?我不是在寻找代码。如果有人能为我提供此问题的算法,我将非常感谢!
非常感谢!:)
为row_index
做一个外循环和col_index
的内环,并在内部循环中串联值。该算法的伪代码:
r := 0
while r < number_of_elements_in(row_index):
c := 0
while c < number_of_elements_in(col_index):
output[r*number_of_elements_in(col_index) + c] := contatenate(col_index[c], row_index[r])
c = c + 1
r = r + 1
可能的实现可能是这样的:
#include <iostream>
#include <vector>
int main() {
std::string row_index = "123456789ABCDEFGHJKL";
std::string col_index = "ABCDEFGHJK";
std::vector<std::string> output;
output.reserve(row_index.size()*col_index.size());
for(auto r : row_index) {
for(auto c : col_index) {
output.emplace_back(std::string() + c + r);
}
}
for(const auto& o : output) // display result
std::cout << o << "n";
}
相关文章:
- 如何在C++中比较两个char数组
- 如何更好地检查两个 char 变量是否在一组值中?
- 在 char* 数组中添加两个索引
- C++函数返回两个 char 数组的相同索引元素
- *char数组到字符串(两次运行代码和两个不同的结果)
- 为什么Xor-ing两个“ char”阵列显示垃圾位
- 如何在C/ C 中比较两个char的两个2D阵列
- 使用"const char*"和"char*"参数连接两个第三方模块
- 在C 中乘以两个char阵列
- 为什么这两个char阵列不相等
- Qthread char阵列在两个线程之间传递后被摧毁
- 在C 中使用两个CHAR变量评估布尔值
- 计数最低号码.char.从两个字符串中删除以使它们成为字眼
- 如何在c++中将计算分解为两个double和一个char
- C ++中的两个'char*'铸件有什么区别
- 比较c++中的两个char
- c++中连接两个char*的函数
- 连接两个char*会产生奇怪的结果
- 在 c++ 中使用 strcmp 比较两个 char 变量显示从 'char' 到 'const char*' 的无效转换
- 如何验证两个char *是否在Google Mock中相等?