b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c++ strchr函数_strchr函数返回_模拟实现strchr函数(18)

电脑杂谈  发布时间:2017-02-28 08:29:56  来源:网络整理

int cmp( const int &a, const int &b)

{

if( a > b )

return 1;

else

return 0;

}

int main()

{

int a[]={3,4,12,1,23,2,1,4};

sort(a,a8); //是对数组a正序排序

for(int i=0;i<8;i)

{

cout<<a[i]<<" ";

}

cout<<endl;

sort(a,a8,cmp); //是对数组a降序排序

for(int i=0;i<8;i)

{

cout<<a[i]<<" ";

}

return 0;

}

输出结果:

1 1 2 3 4 4 12 23

23 12 4 4 3 2 1 1

bool cmp(int a,int b)

{

return a>b;

}

#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

int a[] = {2,1,3};

while (next_permutation(a, a3))

{

cout << a[0] << " " << a[1] << "" << a[2] << endl;

}

return 0;

}

输出结果:2 1 3

2 3 1

3 1 2

3 2 1

#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

string str;

cin >> str;

sort(str.begin(), str.end());

do

{

cout << str <<" ";

}while (next_permutation(str.begin(), str.end()));

return 0;

}

输入:abc

输出结果:abc acbbac bca cab cba

与next_permutation相同

查找两个相邻的等价元素

#include <iostream>

#include <algorithm>

#include <vector>

using namespace std;

bool myfunction (int i, int j)

{

return (i==j);

}

int main ()

{

int myints[] = {10,20,30,30,20,10,10,20};

vector<int> myvector (myints,myints8);

vector<int>::iterator it;

it = adjacent_find (myvector.begin(), myvector.end());

if (it!=myvector.end())

cout << "the first consecutive repeated elements are: "<< *it << endl;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-34960-18.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...