使用reverse反向排列算法
这篇文章发布已经超过两年,部分工具、版本或观点可能已经变化,请结合最新信息判断。
#include <bits/stdc++.h>
using namespace std;
int main()
{
srand(time(NULL));
vector<int>v(10);
for(int i=0;i<10;i++)
{
v[i] = rand()%100;
}
vector<int>::iterator it;
for(it=v.begin();it!=v.end();it++)
{
cout << *it << " ";
}
cout << endl;
reverse(v.begin(),v.end());
for(it=v.begin();it!=v.end();it++)
{
cout << *it << ' ';
}
cout << endl;
return 0;
}
运行结果
94 66 52 71 33 43 91 59 78 69
69 78 59 91 43 33 71 52 66 94
Process returned 0 (0x0) execution time : 0.013 s
Press any key to continue.
string容器
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
s = "123456";
reverse(s.begin(),s.end());
cout << s;
return 0;
}
评论区已延迟加载滑到评论区附近时会自动加载,也可以现在手动打开。



