假设
b = ["good ", "bad "]
a = ["apple","mango"]
then output = ["good apple","good mango","bad apple","bad mango"]
我知道可以使用嵌套的for循环来完成此操作,但是使用C++ STL可以做到这一点吗?
最佳答案
这是单线(从Jonathan Mee's答案posted here复制):
for(size_t i = 0, s = a.size(); i < output.size(); ++i) output[i] = b[i/s] + ' ' + a[i%s];
完整示例here。