算法排序1101001011


algorithm sorting 1101001011

我需要以某种预定义的顺序显示图片和视频。如何从数组中获取输出预定义排序。

$video = ['a1','a2','a3','a4'];
$picture = ['b1','b2','b3','b4'];

排序像 [a,a,b,a,b,b,a,b,a,a];

结果应该是 ['a1','a2','b1','a3','b2','b3',...];

最初C++出现在标签中...测试可以 cpp.sh

#include <iostream>
#include <vector>
int main()
{
    std::string algorithm_sorting ("1101001011");
    std::vector <std::string> video = {"a1","a2","a3","a4"};
    std::vector <std::string> picture = {"b1","b2","b3","b4"};
    std::vector <std::string> result;
    size_t v = 0, p = 0;
    for(auto&x:algorithm_sorting)
    {
        if(x=='1')
        {
            if(v < video.size()) result.push_back(video[v]);
            v++;
        }
        else
        {
            if( p < picture.size()) result.push_back(picture[p]);
            p++;
        }
    }
    for(auto&x:result)std::cout<<x<<" ";
}